+ stream_state = create_stream_state(stream);
+ if (!stream_state) {
+ abort();
+ }
+
+ g_hash_table_insert(iterator->stream_states,
+ (void *) stream, stream_state);
+ stream_state->expected_notif_seq_num++;
+ goto end;
+ }
+
+ if (stream_state->is_ended) {
+ /*
+ * There's a new notification which has a reference to a
+ * stream which, from this iterator's point of view, is
+ * ended ("end of stream" notification was returned).
+ * This is bad: the API guarantees that it can never
+ * happen.
+ */
+ BT_ASSERT_PRE_MSG("Stream is already ended: %![stream-]+s",
+ stream);
+ is_valid = false;
+ goto end;
+ }
+
+ if (notif->seq_num == -1ULL) {
+ notif->seq_num = stream_state->expected_notif_seq_num;
+ }
+
+ if (notif->seq_num != -1ULL &&
+ notif->seq_num != stream_state->expected_notif_seq_num) {
+ BT_ASSERT_PRE_MSG("Unexpected notification sequence number: "
+ "seq-num=%" PRIu64 ", "
+ "expected-seq-num=%" PRIu64 ", %![stream-]+s",
+ notif->seq_num, stream_state->expected_notif_seq_num,
+ stream);
+ is_valid = false;
+ goto end;
+ }
+
+ switch (notif->type) {
+ case BT_NOTIFICATION_TYPE_STREAM_BEGIN:
+ BT_ASSERT_PRE_MSG("Unexpected BT_NOTIFICATION_TYPE_STREAM_BEGIN "
+ "notification at this point: notif-seq-num=%" PRIu64 ", "
+ "%![stream-]+s", notif->seq_num, stream);
+ is_valid = false;
+ goto end;
+ case BT_NOTIFICATION_TYPE_STREAM_END:
+ if (stream_state->cur_packet) {
+ BT_ASSERT_PRE_MSG("Unexpected BT_NOTIFICATION_TYPE_STREAM_END "
+ "notification: missing a "
+ "BT_NOTIFICATION_TYPE_PACKET_END notification "
+ "prior to this notification: "
+ "notif-seq-num=%" PRIu64 ", "
+ "%![stream-]+s", notif->seq_num, stream);
+ is_valid = false;
+ goto end;
+ }
+ stream_state->expected_notif_seq_num++;
+ stream_state->is_ended = true;
+ goto end;
+ case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
+ if (stream_state->cur_packet) {
+ BT_ASSERT_PRE_MSG("Unexpected BT_NOTIFICATION_TYPE_PACKET_BEGIN "
+ "notification at this point: missing a "
+ "BT_NOTIFICATION_TYPE_PACKET_END notification "
+ "prior to this notification: "
+ "notif-seq-num=%" PRIu64 ", %![stream-]+s, "
+ "%![packet-]+a", notif->seq_num, stream,
+ packet);
+ is_valid = false;
+ goto end;
+ }
+ stream_state->expected_notif_seq_num++;
+ stream_state->cur_packet = packet;
+ bt_object_get_no_null_check(stream_state->cur_packet);
+ goto end;
+ case BT_NOTIFICATION_TYPE_PACKET_END:
+ if (!stream_state->cur_packet) {
+ BT_ASSERT_PRE_MSG("Unexpected BT_NOTIFICATION_TYPE_PACKET_END "
+ "notification at this point: missing a "
+ "BT_NOTIFICATION_TYPE_PACKET_BEGIN notification "
+ "prior to this notification: "
+ "notif-seq-num=%" PRIu64 ", %![stream-]+s, "
+ "%![packet-]+a", notif->seq_num, stream,
+ packet);
+ is_valid = false;
+ goto end;
+ }
+ stream_state->expected_notif_seq_num++;
+ BT_OBJECT_PUT_REF_AND_RESET(stream_state->cur_packet);
+ goto end;
+ case BT_NOTIFICATION_TYPE_EVENT:
+ if (packet != stream_state->cur_packet) {
+ BT_ASSERT_PRE_MSG("Unexpected packet for "
+ "BT_NOTIFICATION_TYPE_EVENT notification: "
+ "notif-seq-num=%" PRIu64 ", %![stream-]+s, "
+ "%![notif-packet-]+a, %![expected-packet-]+a",
+ notif->seq_num, stream,
+ stream_state->cur_packet, packet);