- if (stream_range->set) {
- ret = add_range(group_info, stream_range, "range-ns");
- if (ret) {
- goto end;
- }
+ /*
+ * Since each `struct ctf_fs_ds_file_group` has a sorted array of
+ * `struct ctf_fs_ds_index_entry`, we can compute the stream range from
+ * the timestamp_begin of the first index entry and the timestamp_end
+ * of the last index entry.
+ */
+ BT_ASSERT(group->index);
+ BT_ASSERT(group->index->entries);
+ BT_ASSERT(group->index->entries->len > 0);
+
+ /* First entry. */
+ first_ds_index_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index(
+ group->index->entries, 0);
+
+ /* Last entry. */
+ last_ds_index_entry = (struct ctf_fs_ds_index_entry *) g_ptr_array_index(
+ group->index->entries, group->index->entries->len - 1);
+
+ stream_range->begin_ns = first_ds_index_entry->timestamp_begin_ns;
+ stream_range->end_ns = last_ds_index_entry->timestamp_end_ns;
+
+ /*
+ * If any of the begin and end timestamps is not set it means that
+ * packets don't include `timestamp_begin` _and_ `timestamp_end` fields
+ * in their packet context so we can't set the range.
+ */
+ stream_range->set = stream_range->begin_ns != UINT64_C(-1) &&
+ stream_range->end_ns != UINT64_C(-1);
+
+ ret = add_range(group_info, stream_range, "range-ns");
+ if (ret) {
+ goto end;