+ /*
+ * If this event's stream does not support packets, then we
+ * lazily create artificial packets.
+ *
+ * The size of an artificial packet is arbitrarily at least
+ * 4 MiB (it usually is greater because we close it when
+ * comes the time to write a new event and the packet's content
+ * size is >= 4 MiB), except the last one which can be smaller.
+ */
+ if (G_UNLIKELY(!stream->sc->has_packets)) {
+ if (stream->packet_state.is_open &&
+ bt_ctfser_get_offset_in_current_packet_bits(&stream->ctfser) / 8 >=
+ 4 * 1024 * 1024) {
+ /*
+ * Stream's current packet is larger than 4 MiB:
+ * close it. A new packet will be opened just
+ * below.
+ */
+ ret = fs_sink_stream_close_packet(stream, NULL);
+ if (ret) {
+ status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+ goto end;
+ }
+ }
+
+ if (!stream->packet_state.is_open) {
+ /* Stream's packet is not currently opened: open it */
+ ret = fs_sink_stream_open_packet(stream, NULL, NULL);
+ if (ret) {
+ status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
+ goto end;
+ }
+ }
+ }
+
+ BT_ASSERT(stream->packet_state.is_open);