Fix: flt.utils.muxer: make sure message's default clock class exists
[deliverable/babeltrace.git] / plugins / utils / muxer / muxer.c
index 700789520fee6d2ea2df02a5da90a708a3106aa9..607023b2cd2dc9d9a501ab75eb534d4ec9db582d 100644 (file)
@@ -614,6 +614,7 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp,
        const unsigned char *cc_uuid;
        const char *cc_name;
        bt_clock_snapshot_state cs_state = BT_CLOCK_SNAPSHOT_STATE_KNOWN;
+       bt_message_stream_activity_clock_snapshot_state sa_cs_state;
 
        BT_ASSERT(msg);
        BT_ASSERT(ts_ns);
@@ -625,10 +626,84 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp,
 
        switch (bt_message_get_type(msg)) {
        case BT_MESSAGE_TYPE_EVENT:
+               clock_class =
+                       bt_message_event_borrow_stream_class_default_clock_class_const(
+                               msg);
+               if (!clock_class) {
+                       goto no_clock_snapshot;
+               }
+
                cs_state = bt_message_event_borrow_default_clock_snapshot_const(
                        msg, &clock_snapshot);
                break;
+       case BT_MESSAGE_TYPE_PACKET_BEGINNING:
+               bt_message_packet_beginning_borrow_stream_class_default_clock_class_const(
+                       msg);
+               if (!clock_class) {
+                       goto no_clock_snapshot;
+               }
+
+               cs_state = bt_message_packet_beginning_borrow_default_clock_snapshot_const(
+                       msg, &clock_snapshot);
+               break;
+       case BT_MESSAGE_TYPE_PACKET_END:
+               bt_message_packet_end_borrow_stream_class_default_clock_class_const(
+                       msg);
+               if (!clock_class) {
+                       goto no_clock_snapshot;
+               }
+
+               cs_state = bt_message_packet_end_borrow_default_clock_snapshot_const(
+                       msg, &clock_snapshot);
+               break;
+       case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
+               bt_message_discarded_events_borrow_stream_class_default_clock_class_const(
+                       msg);
+               if (!clock_class) {
+                       goto no_clock_snapshot;
+               }
+
+               cs_state = bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
+                       msg, &clock_snapshot);
+               break;
+       case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
+               bt_message_discarded_packets_borrow_stream_class_default_clock_class_const(
+                       msg);
+               if (!clock_class) {
+                       goto no_clock_snapshot;
+               }
+
+               cs_state = bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
+                       msg, &clock_snapshot);
+               break;
+       case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
+               bt_message_stream_activity_beginning_borrow_stream_class_default_clock_class_const(
+                       msg);
+               if (!clock_class) {
+                       goto no_clock_snapshot;
+               }
 
+               sa_cs_state = bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
+                       msg, &clock_snapshot);
+               if (sa_cs_state != BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN) {
+                       goto no_clock_snapshot;
+               }
+
+               break;
+       case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
+               bt_message_stream_activity_end_borrow_stream_class_default_clock_class_const(
+                       msg);
+               if (!clock_class) {
+                       goto no_clock_snapshot;
+               }
+
+               sa_cs_state = bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
+                       msg, &clock_snapshot);
+               if (sa_cs_state != BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN) {
+                       goto no_clock_snapshot;
+               }
+
+               break;
        case BT_MESSAGE_TYPE_INACTIVITY:
                cs_state =
                        bt_message_inactivity_borrow_default_clock_snapshot_const(
@@ -647,18 +722,6 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp,
                goto end;
        }
 
-       /*
-        * If the clock snapshot is missing, then we consider that this
-        * message has no time. In this case it's always the
-        * youngest.
-        */
-       if (!clock_snapshot) {
-               BT_LOGV_STR("Message's default clock snapshot is missing: "
-                       "using the last returned timestamp.");
-               *ts_ns = last_returned_ts_ns;
-               goto end;
-       }
-
        clock_class = bt_clock_snapshot_borrow_clock_class_const(clock_snapshot);
        BT_ASSERT(clock_class);
        cc_uuid = bt_clock_class_get_uuid(clock_class);
@@ -821,6 +884,12 @@ int get_msg_ts_ns(struct muxer_comp *muxer_comp,
 
        goto end;
 
+no_clock_snapshot:
+       BT_LOGV_STR("Message's default clock snapshot is missing: "
+               "using the last returned timestamp.");
+       *ts_ns = last_returned_ts_ns;
+       goto end;
+
 error:
        ret = -1;
 
@@ -1459,3 +1528,53 @@ bt_self_component_status muxer_input_port_connected(
 end:
        return status;
 }
+
+BT_HIDDEN
+bt_bool muxer_msg_iter_can_seek_beginning(
+               bt_self_message_iterator *self_msg_iter)
+{
+       struct muxer_msg_iter *muxer_msg_iter =
+               bt_self_message_iterator_get_data(self_msg_iter);
+       uint64_t i;
+       bt_bool ret = BT_TRUE;
+
+       for (i = 0; i < muxer_msg_iter->muxer_upstream_msg_iters->len; i++) {
+               struct muxer_upstream_msg_iter *upstream_msg_iter =
+                       muxer_msg_iter->muxer_upstream_msg_iters->pdata[i];
+
+               if (!bt_self_component_port_input_message_iterator_can_seek_beginning(
+                               upstream_msg_iter->msg_iter)) {
+                       ret = BT_FALSE;
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
+
+BT_HIDDEN
+bt_self_message_iterator_status muxer_msg_iter_seek_beginning(
+               bt_self_message_iterator *self_msg_iter)
+{
+       struct muxer_msg_iter *muxer_msg_iter =
+               bt_self_message_iterator_get_data(self_msg_iter);
+       int status;
+       uint64_t i;
+
+       for (i = 0; i < muxer_msg_iter->muxer_upstream_msg_iters->len; i++) {
+               struct muxer_upstream_msg_iter *upstream_msg_iter =
+                       muxer_msg_iter->muxer_upstream_msg_iters->pdata[i];
+
+               status = bt_self_component_port_input_message_iterator_seek_beginning(
+                       upstream_msg_iter->msg_iter);
+               if (status != BT_MESSAGE_ITERATOR_STATUS_OK) {
+                       goto end;
+               }
+       }
+
+       muxer_msg_iter->last_returned_ts_ns = INT64_MIN;
+
+end:
+       return status;
+}
This page took 0.028421 seconds and 5 git commands to generate.