+static
+struct ctf_fs_ds_index *ctf_fs_ds_index_create(size_t length)
+{
+ struct ctf_fs_ds_index *index = g_new0(struct ctf_fs_ds_index, 1);
+
+ if (!index) {
+ BT_LOGE_STR("Failed to allocate index");
+ goto error;
+ }
+
+ index->entries = g_array_sized_new(FALSE, TRUE,
+ sizeof(struct ctf_fs_ds_index_entry), length);
+ if (!index->entries) {
+ BT_LOGE("Failed to allocate %zu index entries.", length);
+ goto error;
+ }
+ g_array_set_size(index->entries, length);
+end:
+ return index;
+error:
+ ctf_fs_ds_index_destroy(index);
+ goto end;
+}
+
+static
+struct bt_ctf_clock_class *get_field_mapped_clock_class(
+ struct bt_ctf_field *field)
+{
+ struct bt_ctf_field_type *field_type;
+ struct bt_ctf_clock_class *clock_class = NULL;
+
+ field_type = bt_ctf_field_get_type(field);
+ if (!field_type) {
+ goto end;
+ }
+
+ clock_class = bt_ctf_field_type_integer_get_mapped_clock_class(
+ field_type);
+ if (!clock_class) {
+ goto end;
+ }
+end:
+ bt_put(field_type);
+ return clock_class;
+}
+
+static
+int get_ds_file_packet_bounds_clock_classes(struct ctf_fs_ds_file *ds_file,
+ struct bt_ctf_clock_class **_timestamp_begin_cc,
+ struct bt_ctf_clock_class **_timestamp_end_cc)
+{
+ int ret;
+ struct bt_ctf_field *timestamp_field = NULL;
+ struct bt_ctf_field *packet_context_field = NULL;
+ struct bt_ctf_clock_class *timestamp_begin_cc = NULL;
+ struct bt_ctf_clock_class *timestamp_end_cc = NULL;
+
+ ret = ctf_fs_ds_file_get_packet_header_context_fields(ds_file,
+ NULL, &packet_context_field);
+ if (ret || !packet_context_field) {
+ BT_LOGD("Cannot retrieve packet context field of stream \'%s\'",
+ ds_file->file->path->str);
+ ret = -1;
+ goto end;
+ }
+
+ timestamp_field = bt_ctf_field_structure_get_field_by_name(
+ packet_context_field, "timestamp_begin");
+ if (!timestamp_field) {
+ BT_LOGD("Cannot retrieve timestamp_begin field in packet context of stream \'%s\'",
+ ds_file->file->path->str);
+ ret = -1;
+ goto end;
+ }
+
+ timestamp_begin_cc = get_field_mapped_clock_class(timestamp_field);
+ if (!timestamp_begin_cc) {
+ BT_LOGD("Cannot retrieve the clock mapped to timestamp_begin of stream \'%s\'",
+ ds_file->file->path->str);
+ }
+ BT_PUT(timestamp_field);
+
+ timestamp_field = bt_ctf_field_structure_get_field_by_name(
+ packet_context_field, "timestamp_end");
+ if (!timestamp_field) {
+ BT_LOGD("Cannot retrieve timestamp_end field in packet context of stream \'%s\'",
+ ds_file->file->path->str);
+ ret = -1;
+ goto end;
+ }
+
+ timestamp_end_cc = get_field_mapped_clock_class(timestamp_field);
+ if (!timestamp_end_cc) {
+ BT_LOGD("Cannot retrieve the clock mapped to timestamp_end in stream \'%s\'",
+ ds_file->file->path->str);
+ }
+
+ if (_timestamp_begin_cc) {
+ *_timestamp_begin_cc = bt_get(timestamp_begin_cc);
+ }
+ if (_timestamp_end_cc) {
+ *_timestamp_end_cc = bt_get(timestamp_end_cc);
+ }
+end:
+ bt_put(packet_context_field);
+ bt_put(timestamp_field);
+ bt_put(timestamp_begin_cc);
+ bt_put(timestamp_end_cc);
+ return ret;
+}