+static
+bt_component_class_message_iterator_next_method_status
+create_stream_state_entry(
+ struct trimmer_iterator *trimmer_it,
+ const struct bt_stream *stream,
+ struct trimmer_iterator_stream_state **stream_state)
+{
+ struct trimmer_comp *trimmer_comp = trimmer_it->trimmer_comp;
+ bt_component_class_message_iterator_next_method_status status;
+ struct trimmer_iterator_stream_state *sstate;
+ const bt_stream_class *sc;
+
+ BT_ASSERT(!bt_g_hash_table_contains(trimmer_it->stream_states, stream));
+
+ /*
+ * Validate right now that the stream's class
+ * has a registered default clock class so that
+ * an existing stream state guarantees existing
+ * default clock snapshots for its associated
+ * messages.
+ *
+ * Also check that clock snapshots are always
+ * known.
+ */
+ sc = bt_stream_borrow_class_const(stream);
+ if (!bt_stream_class_borrow_default_clock_class_const(sc)) {
+ BT_COMP_LOGE("Unsupported stream: stream class does "
+ "not have a default clock class: "
+ "stream-addr=%p, "
+ "stream-id=%" PRIu64 ", "
+ "stream-name=\"%s\"",
+ stream, bt_stream_get_id(stream),
+ bt_stream_get_name(stream));
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
+ goto end;
+ }
+
+ /*
+ * Temporary: make sure packet beginning, packet
+ * end, discarded events, and discarded packets
+ * messages have default clock snapshots until
+ * the support for not having them is
+ * implemented.
+ */
+ if (!bt_stream_class_packets_have_beginning_default_clock_snapshot(
+ sc)) {
+ BT_COMP_LOGE("Unsupported stream: packets have "
+ "no beginning clock snapshot: "
+ "stream-addr=%p, "
+ "stream-id=%" PRIu64 ", "
+ "stream-name=\"%s\"",
+ stream, bt_stream_get_id(stream),
+ bt_stream_get_name(stream));
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
+ goto end;
+ }
+
+ if (!bt_stream_class_packets_have_end_default_clock_snapshot(
+ sc)) {
+ BT_COMP_LOGE("Unsupported stream: packets have "
+ "no end clock snapshot: "
+ "stream-addr=%p, "
+ "stream-id=%" PRIu64 ", "
+ "stream-name=\"%s\"",
+ stream, bt_stream_get_id(stream),
+ bt_stream_get_name(stream));
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
+ goto end;
+ }
+
+ if (bt_stream_class_supports_discarded_events(sc) &&
+ !bt_stream_class_discarded_events_have_default_clock_snapshots(sc)) {
+ BT_COMP_LOGE("Unsupported stream: discarded events "
+ "have no clock snapshots: "
+ "stream-addr=%p, "
+ "stream-id=%" PRIu64 ", "
+ "stream-name=\"%s\"",
+ stream, bt_stream_get_id(stream),
+ bt_stream_get_name(stream));
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
+ goto end;
+ }
+
+ if (bt_stream_class_supports_discarded_packets(sc) &&
+ !bt_stream_class_discarded_packets_have_default_clock_snapshots(sc)) {
+ BT_COMP_LOGE("Unsupported stream: discarded packets "
+ "have no clock snapshots: "
+ "stream-addr=%p, "
+ "stream-id=%" PRIu64 ", "
+ "stream-name=\"%s\"",
+ stream, bt_stream_get_id(stream),
+ bt_stream_get_name(stream));
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
+ goto end;
+ }
+
+ sstate = g_new0(struct trimmer_iterator_stream_state, 1);
+ if (!sstate) {
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR;
+ goto end;
+ }
+
+ sstate->stream = stream;
+
+ g_hash_table_insert(trimmer_it->stream_states, (void *) stream, sstate);
+
+ *stream_state = sstate;
+
+ status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
+
+end:
+ return status;
+}
+
+static
+struct trimmer_iterator_stream_state *get_stream_state_entry(
+ struct trimmer_iterator *trimmer_it,
+ const struct bt_stream *stream)
+{
+ struct trimmer_iterator_stream_state *sstate;
+
+ BT_ASSERT(stream);
+ sstate = g_hash_table_lookup(trimmer_it->stream_states, stream);
+ BT_ASSERT(sstate);
+
+ return sstate;
+}
+