-static
-uint64_t get_packet_header_stream_instance_id(struct ctf_fs_trace *ctf_fs_trace,
- struct bt_ctf_field *packet_header_field)
-{
- struct bt_ctf_field *stream_instance_id_field = NULL;
- uint64_t stream_instance_id = -1ULL;
- int ret;
-
- if (!packet_header_field) {
- goto end;
- }
-
- stream_instance_id_field = bt_ctf_field_structure_get_field_by_name(
- packet_header_field, "stream_instance_id");
- if (!stream_instance_id_field) {
- goto end;
- }
-
- ret = bt_ctf_field_unsigned_integer_get_value(stream_instance_id_field,
- &stream_instance_id);
- if (ret) {
- stream_instance_id = -1ULL;
- goto end;
- }
-
-end:
- bt_put(stream_instance_id_field);
- return stream_instance_id;
-}
-
-struct bt_ctf_stream_class *stream_class_from_packet_header(
- struct ctf_fs_trace *ctf_fs_trace,
- struct bt_ctf_field *packet_header_field)
-{
- struct bt_ctf_field *stream_id_field = NULL;
- struct bt_ctf_stream_class *stream_class = NULL;
- uint64_t stream_id = -1ULL;
- int ret;
-
- if (!packet_header_field) {
- goto single_stream_class;
- }
-
- stream_id_field = bt_ctf_field_structure_get_field_by_name(
- packet_header_field, "stream_id");
- if (!stream_id_field) {
- goto single_stream_class;
- }
-
- ret = bt_ctf_field_unsigned_integer_get_value(stream_id_field,
- &stream_id);
- if (ret) {
- stream_id = -1ULL;
- }
-
- if (stream_id == -1ULL) {
-single_stream_class:
- /* Single stream class */
- if (bt_ctf_trace_get_stream_class_count(
- ctf_fs_trace->metadata->trace) == 0) {
- goto end;
- }
-
- stream_class = bt_ctf_trace_get_stream_class_by_index(
- ctf_fs_trace->metadata->trace, 0);
- } else {
- stream_class = bt_ctf_trace_get_stream_class_by_id(
- ctf_fs_trace->metadata->trace, stream_id);
- }
-
-end:
- bt_put(stream_id_field);
- return stream_class;
-}
-
-uint64_t get_packet_context_timestamp_begin_ns(
- struct ctf_fs_trace *ctf_fs_trace,
- struct bt_ctf_field *packet_context_field)
-{
- int ret;
- struct bt_ctf_field *timestamp_begin_field = NULL;
- struct bt_ctf_field_type *timestamp_begin_ft = NULL;
- uint64_t timestamp_begin_raw_value = -1ULL;
- uint64_t timestamp_begin_ns = -1ULL;
- int64_t timestamp_begin_ns_signed;
- struct bt_ctf_clock_class *timestamp_begin_clock_class = NULL;
- struct bt_ctf_clock_value *clock_value = NULL;
-
- if (!packet_context_field) {
- goto end;
- }
-
- timestamp_begin_field = bt_ctf_field_structure_get_field_by_name(
- packet_context_field, "timestamp_begin");
- if (!timestamp_begin_field) {
- goto end;
- }
-
- timestamp_begin_ft = bt_ctf_field_get_type(timestamp_begin_field);
- assert(timestamp_begin_ft);
- timestamp_begin_clock_class =
- bt_ctf_field_type_integer_get_mapped_clock_class(timestamp_begin_ft);
- if (!timestamp_begin_clock_class) {
- goto end;
- }
-
- ret = bt_ctf_field_unsigned_integer_get_value(timestamp_begin_field,
- ×tamp_begin_raw_value);
- if (ret) {
- goto end;
- }
-
- clock_value = bt_ctf_clock_value_create(timestamp_begin_clock_class,
- timestamp_begin_raw_value);
- if (!clock_value) {
- goto end;
- }
-
- ret = bt_ctf_clock_value_get_value_ns_from_epoch(clock_value,
- ×tamp_begin_ns_signed);
- if (ret) {
- goto end;
- }
-
- timestamp_begin_ns = (uint64_t) timestamp_begin_ns_signed;
-
-end:
- bt_put(timestamp_begin_field);
- bt_put(timestamp_begin_ft);
- bt_put(timestamp_begin_clock_class);
- bt_put(clock_value);
- return timestamp_begin_ns;
-}
-