From: Antonio Ospite Date: Mon, 2 Oct 2017 20:33:35 +0000 (+0200) Subject: Expand snd_seq_create_simple_port() and use a queue to timestamp events X-Git-Url: https://git.ao2.it/gst-aseq-appsrc.git/commitdiff_plain/e01610203967b299c3dcb06c957657d4f8430df9?ds=inline Expand snd_seq_create_simple_port() and use a queue to timestamp events Events are timestamped with a real-time value representing the time passed since the queue timer was started. The timestamp is not used just yet. --- diff --git a/gst-aseq-appsrc.c b/gst-aseq-appsrc.c index 506409e..1577ebf 100644 --- a/gst-aseq-appsrc.c +++ b/gst-aseq-appsrc.c @@ -51,6 +51,7 @@ struct _App GMainLoop *loop; snd_seq_t *seq; + int queue; int port_count; snd_seq_addr_t *seq_ports; snd_midi_event_t *parser; @@ -143,17 +144,52 @@ out_free_ports_list: } static int +start_queue_timer (snd_seq_t *seq, int queue) +{ + int ret; + + ret = snd_seq_start_queue (seq, queue, NULL); + if (ret < 0) { + GST_ERROR ("Timer event output error: %s\n", snd_strerror (ret)); + return ret; + } + + ret = snd_seq_drain_output (seq); + if (ret < 0) + GST_ERROR ("Drain output error: %s\n", snd_strerror (ret)); + + return ret; +} + +static int create_port (App * app) { + snd_seq_port_info_t *pinfo; int ret; - ret = snd_seq_create_simple_port (app->seq, DEFAULT_CLIENT_NAME, - SND_SEQ_PORT_CAP_WRITE | - SND_SEQ_PORT_CAP_SUBS_WRITE, - SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION); + snd_seq_port_info_alloca (&pinfo); + snd_seq_port_info_set_name (pinfo, DEFAULT_CLIENT_NAME); + snd_seq_port_info_set_type (pinfo, SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION); + snd_seq_port_info_set_capability (pinfo, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE); + + ret = snd_seq_alloc_queue (app->seq); + if (ret < 0) { + GST_ERROR ("Cannot allocate queue: %s\n", snd_strerror (ret)); + return ret; + } + + app->queue = ret; + + snd_seq_port_info_set_timestamping (pinfo, 1); + snd_seq_port_info_set_timestamp_real (pinfo, 1); + snd_seq_port_info_set_timestamp_queue (pinfo, app->queue); + + ret = snd_seq_create_port (app->seq, pinfo); if (ret < 0) GST_ERROR ("Cannot create port - %s", snd_strerror (ret)); + ret = start_queue_timer (app->seq, app->queue); + return ret; }