- /* Set the default context attributes if present and unset. */
- if (!get_event_header_timestamp(
- ((struct bt_ctf_event *) g_ptr_array_index(
- stream->events, 0))->event_header, ×tamp_begin)) {
+ if (stream->packet_context) {
+ /* Set the default context attributes if present and unset. */
+ if (!empty_packet && !get_event_header_timestamp(
+ ((struct bt_ctf_event *) g_ptr_array_index(
+ stream->events, 0))->event_header, ×tamp_begin)) {
+ ret = set_structure_field_integer(stream->packet_context,
+ "timestamp_begin", timestamp_begin);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ if (!empty_packet && !get_event_header_timestamp(
+ ((struct bt_ctf_event *) g_ptr_array_index(
+ stream->events, stream->events->len - 1))->event_header,
+ ×tamp_end)) {
+
+ ret = set_structure_field_integer(stream->packet_context,
+ "timestamp_end", timestamp_end);
+ if (ret) {
+ goto end;
+ }
+ }