1 | |
---|
2 | #include <gst/gst.h> |
---|
3 | #include <string.h> |
---|
4 | |
---|
5 | static GstPad *sinesrcpad; |
---|
6 | |
---|
7 | static GstStaticCaps caps1 = GST_STATIC_CAPS ("audio/x-raw-int, " |
---|
8 | "endianness=(int)1234, " |
---|
9 | "signed=(boolean)true, " |
---|
10 | "width=(int)16, " "depth=(int)16, " "rate=(int)48000, " "channels=(int)1"); |
---|
11 | static GstStaticCaps caps2 = GST_STATIC_CAPS ("audio/x-raw-int, " |
---|
12 | "endianness=(int)1234, " |
---|
13 | "signed=(boolean)true, " |
---|
14 | "width=(int)16, " "depth=(int)16, " "rate=(int)44100, " "channels=(int)1"); |
---|
15 | |
---|
16 | int stage = 0; |
---|
17 | |
---|
18 | static GstCaps * |
---|
19 | my_fixate (GstPad * pad, GstCaps * caps, gpointer user_data) |
---|
20 | { |
---|
21 | const char *element_name; |
---|
22 | const char *pad_name; |
---|
23 | |
---|
24 | element_name = gst_element_get_name (gst_pad_get_parent (pad)); |
---|
25 | pad_name = gst_pad_get_name (pad); |
---|
26 | |
---|
27 | g_print ("%s:%s: %s\n", element_name, pad_name, gst_caps_to_string (caps)); |
---|
28 | |
---|
29 | if (strcmp (element_name, "sinesrc0") == 0 && strcmp (pad_name, "src") == 0) { |
---|
30 | GstCaps *icaps; |
---|
31 | const GstCaps *mycaps; |
---|
32 | int rate; |
---|
33 | |
---|
34 | sinesrcpad = pad; |
---|
35 | |
---|
36 | if (stage == 0) { |
---|
37 | mycaps = gst_static_caps_get (&caps1); |
---|
38 | rate = 48000; |
---|
39 | } else { |
---|
40 | mycaps = gst_static_caps_get (&caps2); |
---|
41 | rate = 44100; |
---|
42 | } |
---|
43 | icaps = gst_caps_intersect (caps, mycaps); |
---|
44 | if (!gst_caps_is_empty (icaps)) { |
---|
45 | gst_caps_free (icaps); |
---|
46 | g_print ("returning %d\n", rate); |
---|
47 | return gst_caps_copy (mycaps); |
---|
48 | } |
---|
49 | gst_caps_free (icaps); |
---|
50 | } |
---|
51 | |
---|
52 | return NULL; |
---|
53 | } |
---|
54 | |
---|
55 | int |
---|
56 | main (int argc, char *argv[]) |
---|
57 | { |
---|
58 | GstElement *pipeline; |
---|
59 | const GList *list; |
---|
60 | const GList *l2; |
---|
61 | int i; |
---|
62 | int ret; |
---|
63 | GError *error = NULL; |
---|
64 | |
---|
65 | gst_init (&argc, &argv); |
---|
66 | |
---|
67 | /* change sinesrk to sinesrc once gst_parse_launch is fixed */ |
---|
68 | pipeline = gst_parse_launch ("sinesrc ! audioconvert ! " |
---|
69 | "audio/x-raw-int, channels=2, rate=48000;" |
---|
70 | "audio/x-raw-int, channels=1, rate=44100 !" "fakesink", &error); |
---|
71 | |
---|
72 | if (error != NULL) { |
---|
73 | g_print |
---|
74 | ("oops, couldn't build pipeline. You probably don't have audioconvert or sinesrc\n" |
---|
75 | "the error was: %s\n", error->message); |
---|
76 | g_error_free (error); |
---|
77 | exit (0); |
---|
78 | } |
---|
79 | |
---|
80 | list = gst_bin_get_list (GST_BIN (pipeline)); |
---|
81 | while (list) { |
---|
82 | GstElement *element = GST_ELEMENT (list->data); |
---|
83 | |
---|
84 | l2 = gst_element_get_pad_list (element); |
---|
85 | while (l2) { |
---|
86 | GstPad *pad = GST_PAD (l2->data); |
---|
87 | |
---|
88 | if (gst_pad_get_direction (pad) == GST_PAD_SRC) { |
---|
89 | g_signal_connect (G_OBJECT (pad), "fixate", G_CALLBACK (my_fixate), |
---|
90 | NULL); |
---|
91 | } |
---|
92 | l2 = g_list_next (l2); |
---|
93 | } |
---|
94 | list = g_list_next (list); |
---|
95 | } |
---|
96 | |
---|
97 | g_signal_connect (pipeline, "deep_notify", |
---|
98 | G_CALLBACK (gst_element_default_deep_notify), NULL); |
---|
99 | |
---|
100 | gst_element_set_state (pipeline, GST_STATE_PLAYING); |
---|
101 | i = 0; |
---|
102 | while (1) { |
---|
103 | gst_bin_iterate (GST_BIN (pipeline)); |
---|
104 | i++; |
---|
105 | if (i == 10) { |
---|
106 | stage = 1; |
---|
107 | g_print ("10 iterations\n"); |
---|
108 | ret = gst_pad_renegotiate (sinesrcpad); |
---|
109 | g_print ("negotiation returned %d\n", ret); |
---|
110 | } |
---|
111 | if (i == 20) { |
---|
112 | g_print ("20 iterations\n"); |
---|
113 | exit (0); |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | return 0; |
---|
118 | } |
---|