- 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;
+ if (msg_ns_from_origin >= ns_from_origin) {
+ *got_first = true;
+ goto push_msg;
+ }
+
+ ret = bt_clock_snapshot_get_ns_from_origin(
+ msg_disc_items->default_end_cs,
+ &msg_ns_from_origin);
+ if (ret) {
+ status = BT_MESSAGE_ITERATOR_STATUS_ERROR;
+ goto end;
+ }
+
+ if (msg_ns_from_origin >= ns_from_origin) {
+ /*
+ * The discarded items message's beginning time
+ * is before the requested seeking time, but its
+ * end time is after. Modify the message so as
+ * to set its beginning time to the requested
+ * seeking time, and make its item count unknown
+ * as we don't know if items were really
+ * discarded within the new time range.
+ */
+ uint64_t new_begin_raw_value;
+
+ ret = bt_clock_class_clock_value_from_ns_from_origin(
+ msg_disc_items->default_end_cs->clock_class,
+ ns_from_origin, &new_begin_raw_value);
+ if (ret) {
+ status = BT_MESSAGE_ITERATOR_STATUS_ERROR;
+ goto end;
+ }
+
+ bt_clock_snapshot_set_raw_value(
+ msg_disc_items->default_begin_cs,
+ new_begin_raw_value);
+ msg_disc_items->count.base.avail =
+ BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE;
+
+ /*
+ * It is safe to push it because its beginning
+ * time is exactly the requested seeking time.
+ */
+ goto push_msg;
+ } else {
+ goto skip_msg;
+ }