+ /* This message won't be sent downstream. */
+ switch (msg->type) {
+ case BT_MESSAGE_TYPE_STREAM_BEGINNING:
+ {
+ const struct bt_message_stream *stream_msg = (const void *) msg;
+ struct auto_seek_stream_state *stream_state;
+ gboolean did_not_exist;
+
+ /* Update stream's state: stream began. */
+ stream_state = create_auto_seek_stream_state();
+ if (!stream_state) {
+ status = BT_MESSAGE_ITERATOR_STATUS_NOMEM;
+ goto end;
+ }
+
+ stream_state->state = AUTO_SEEK_STREAM_STATE_STREAM_BEGAN;
+ did_not_exist = g_hash_table_insert(stream_states, stream_msg->stream, stream_state);
+ BT_ASSERT(did_not_exist);
+ break;
+ }
+ case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
+ {
+ const struct bt_message_stream_activity *stream_act_msg =
+ (const void *) msg;
+ struct auto_seek_stream_state *stream_state;
+
+ /* Update stream's state: stream activity began. */
+ stream_state = g_hash_table_lookup(stream_states, stream_act_msg->stream);
+ BT_ASSERT(stream_state);
+
+ BT_ASSERT(stream_state->state == AUTO_SEEK_STREAM_STATE_STREAM_BEGAN);
+ stream_state->state = AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN;
+ BT_ASSERT(!stream_state->packet);
+ break;
+ }
+ case BT_MESSAGE_TYPE_PACKET_BEGINNING:
+ {
+ const struct bt_message_packet *packet_msg =
+ (const void *) msg;
+ struct auto_seek_stream_state *stream_state;
+
+ /* Update stream's state: packet began. */
+ stream_state = g_hash_table_lookup(stream_states, packet_msg->packet->stream);
+ BT_ASSERT(stream_state);
+
+ BT_ASSERT(stream_state->state == AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN);
+ stream_state->state = AUTO_SEEK_STREAM_STATE_PACKET_BEGAN;
+ BT_ASSERT(!stream_state->packet);
+ stream_state->packet = packet_msg->packet;
+ break;
+ }
+ case BT_MESSAGE_TYPE_PACKET_END:
+ {
+ const struct bt_message_packet *packet_msg =
+ (const void *) msg;
+ struct auto_seek_stream_state *stream_state;
+
+ /* Update stream's state: packet ended. */
+ stream_state = g_hash_table_lookup(stream_states, packet_msg->packet->stream);
+ BT_ASSERT(stream_state);
+
+ BT_ASSERT(stream_state->state == AUTO_SEEK_STREAM_STATE_PACKET_BEGAN);
+ stream_state->state = AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN;
+ BT_ASSERT(stream_state->packet);
+ stream_state->packet = NULL;
+ break;
+ }
+ case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
+ {
+ const struct bt_message_stream_activity *stream_act_msg =
+ (const void *) msg;
+ struct auto_seek_stream_state *stream_state;
+
+ /* Update stream's state: stream activity ended. */
+ stream_state = g_hash_table_lookup(stream_states, stream_act_msg->stream);
+ BT_ASSERT(stream_state);
+
+ BT_ASSERT(stream_state->state == AUTO_SEEK_STREAM_STATE_STREAM_ACTIVITY_BEGAN);
+ stream_state->state = AUTO_SEEK_STREAM_STATE_STREAM_BEGAN;
+ BT_ASSERT(!stream_state->packet);
+ break;
+ }
+ case BT_MESSAGE_TYPE_STREAM_END:
+ {
+ const struct bt_message_stream *stream_msg = (const void *) msg;
+ struct auto_seek_stream_state *stream_state;
+
+ stream_state = g_hash_table_lookup(stream_states, stream_msg->stream);
+ BT_ASSERT(stream_state);
+ BT_ASSERT(stream_state->state == AUTO_SEEK_STREAM_STATE_STREAM_BEGAN);
+ BT_ASSERT(!stream_state->packet);
+
+ /* Update stream's state: this stream doesn't exist anymore. */
+ g_hash_table_remove(stream_states, stream_msg->stream);
+ break;
+ }
+ default:
+ break;
+ }
+