+ case GST_MESSAGE_STATE_CHANGED:
+ {
+ GstState old_state, new_state;
+
+ gst_message_parse_state_changed (message, &old_state, &new_state, NULL);
+ if (new_state == GST_STATE_PLAYING) {
+ GstClockTime gst_time;
+ GstClockTime base_time;
+ GstClockTime running_time;
+ GstClockTime queue_time;
+ GstClock *clock;
+ snd_seq_queue_status_t *status;
+
+ if (app->tick == 0) {
+ start_queue_timer (app->seq, app->queue);
+ schedule_tick (app);
+ }
+
+ clock = gst_element_get_clock (GST_ELEMENT (app->appsrc));
+ gst_time = gst_clock_get_time (clock);
+ gst_object_unref (clock);
+ base_time = gst_element_get_base_time (GST_ELEMENT (app->appsrc));
+ running_time = gst_time - base_time;
+
+ snd_seq_queue_status_malloc (&status);
+ snd_seq_get_queue_status (app->seq, 0, status);
+ queue_time = GST_TIMESPEC_TO_TIME (*snd_seq_queue_status_get_real_time (status));
+ snd_seq_queue_status_free (status);
+
+ app->delay = running_time - queue_time;
+ }
+ break;
+ }