Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / tests / examples / jack / jack_client.c
1 /* This app demonstrates the creation and use of a jack client in conjunction
2  * with the jack plugins. This way, an application can control the jack client
3  * directly.
4  */
5
6 #include <gst/gst.h>
7 #include <gtk/gtk.h>
8 #include <jack/jack.h>
9
10 static gboolean
11 quit_cb (gpointer data)
12 {
13   gtk_main_quit ();
14   return FALSE;
15 }
16
17 int
18 main (int argc, char **argv)
19 {
20   jack_client_t *src_client, *sink_client;
21   jack_status_t status;
22   GstElement *pipeline, *src, *sink;
23   GstStateChangeReturn ret;
24
25   gst_init (&argc, &argv);
26
27   /* create jack clients */
28   src_client = jack_client_open ("src_client", JackNoStartServer, &status);
29   if (src_client == NULL) {
30     if (status & JackServerFailed)
31       g_print ("JACK server not running\n");
32     else
33       g_print ("jack_client_open() failed, status = 0x%2.0x\n", status);
34     return 1;
35   }
36
37   sink_client = jack_client_open ("sink_client", JackNoStartServer, &status);
38   if (sink_client == NULL) {
39     if (status & JackServerFailed)
40       g_print ("JACK server not running\n");
41     else
42       g_print ("jack_client_open() failed, status = 0x%2.0x\n", status);
43     return 1;
44   }
45
46   /* create gst elements */
47   pipeline = gst_pipeline_new ("my_pipeline");
48
49   src = gst_element_factory_make ("jackaudiosrc", NULL);
50   sink = gst_element_factory_make ("jackaudiosink", NULL);
51
52   g_object_set (src, "client", src_client, NULL);
53   g_object_set (sink, "client", sink_client, NULL);
54
55   gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
56
57   /* link everything together */
58   if (!gst_element_link (src, sink)) {
59     g_print ("Failed to link elements!\n");
60     return 1;
61   }
62
63   /* run */
64   ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
65   if (ret == GST_STATE_CHANGE_FAILURE) {
66     g_print ("Failed to start up pipeline!\n");
67     return 1;
68   }
69
70   /* quit after 5 seconds */
71   g_timeout_add (5000, (GSourceFunc) quit_cb, NULL);
72   gtk_main ();
73
74   /* clean up */
75   gst_element_set_state (pipeline, GST_STATE_NULL);
76   gst_object_unref (pipeline);
77
78   return 0;
79 }