10 #define ADD_2_STREAMS TRUE
11 #define USE_SECOND_STREAM TRUE
13 static GMainLoop *global_mainloop = NULL;
15 static guint global_components_ready = 0;
16 static guint global_components_ready_exit = 0;
18 static gboolean timer_cb (gpointer pointer)
20 g_debug ("test-different-number-streams:%s: %p", G_STRFUNC, pointer);
22 /* signal status via a global variable */
24 /* note: should not be reached, abort */
25 g_error ("ERROR: test has got stuck, aborting...");
30 static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer data)
32 g_debug ("%p: gathering done (stream_id: %u)", agent, stream_id);
35 static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint component_id, guint state, gpointer data)
37 g_debug ("%p: component state changed (stream_id: %u, component_id: %u, state: %s)",
38 agent, stream_id, component_id, nice_component_state_to_string (state));
40 if (state == NICE_COMPONENT_STATE_READY) {
41 global_components_ready++;
44 /* signal status via a global variable */
45 if (global_components_ready == global_components_ready_exit) {
46 g_debug ("Components ready/failed achieved. Stopping mailoop");
47 g_main_loop_quit (global_mainloop);
51 static void set_candidates (NiceAgent *from, guint from_stream,
52 NiceAgent *to, guint to_stream, guint component)
54 GSList *cands = NULL, *i;
56 cands = nice_agent_get_local_candidates (from, from_stream, component);
57 nice_agent_set_remote_candidates (to, to_stream, component, cands);
59 for (i = cands; i; i = i->next)
60 nice_candidate_free ((NiceCandidate *) i->data);
64 static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, guint len, gchar *buf, gpointer user_data)
66 g_debug ("%p: recv (stream_id: %u, component_id: %u)", agent, stream_id, component_id);
71 NiceAgent *lagent, *ragent;
73 guint ls_id, rs_id_1, rs_id_2;
74 gchar *lufrag = NULL, *lpassword = NULL;
75 gchar *rufrag1 = NULL, *rpassword1 = NULL, *rufrag2 = NULL, *rpassword2 = NULL;
82 WSAStartup(0x0202, &w);
85 /* Initialize nice agents */
86 nice_address_init (&addr);
87 nice_address_set_from_string (&addr, "127.0.0.1");
89 global_mainloop = g_main_loop_new (NULL, FALSE);
91 /* step: create the agents L and R */
92 lagent = nice_agent_new (g_main_loop_get_context (global_mainloop),
93 NICE_COMPATIBILITY_GOOGLE);
94 g_debug ("lagent: %p", lagent);
96 nice_agent_add_local_address (lagent, &addr);
97 nice_agent_set_software (lagent, "test-different-number-streams, Left Agent");
98 g_object_set (G_OBJECT (lagent), "ice-tcp", FALSE, NULL);
99 g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
100 g_object_set (G_OBJECT (lagent), "upnp", FALSE, NULL);
101 g_signal_connect (G_OBJECT (lagent), "candidate-gathering-done",
102 G_CALLBACK (cb_candidate_gathering_done), NULL);
103 g_signal_connect (G_OBJECT (lagent), "component-state-changed",
104 G_CALLBACK (cb_component_state_changed), NULL);
106 ragent = nice_agent_new (g_main_loop_get_context (global_mainloop),
107 NICE_COMPATIBILITY_GOOGLE);
108 g_debug ("ragent: %p", ragent);
110 nice_agent_add_local_address (ragent, &addr);
111 nice_agent_set_software (ragent, "test-different-number-streams, Right Agent");
112 g_object_set (G_OBJECT (ragent), "ice-tcp", FALSE, NULL);
113 g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);
114 g_object_set (G_OBJECT (ragent), "upnp", FALSE, NULL);
115 g_signal_connect (G_OBJECT (ragent), "candidate-gathering-done",
116 G_CALLBACK (cb_candidate_gathering_done), NULL);
117 g_signal_connect (G_OBJECT (ragent), "component-state-changed",
118 G_CALLBACK (cb_component_state_changed), NULL);
120 /* step: add a timer to catch state changes triggered by signals */
121 timer_id = g_timeout_add (30000, timer_cb, NULL);
123 ls_id = nice_agent_add_stream (lagent, 2);
124 g_assert_cmpuint (ls_id, >, 0);
125 nice_agent_get_local_credentials(lagent, ls_id, &lufrag, &lpassword);
127 /* step: attach to mainloop (needed to register the fds) */
128 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
129 g_main_loop_get_context (global_mainloop), cb_nice_recv, NULL);
130 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP,
131 g_main_loop_get_context (global_mainloop), cb_nice_recv, NULL);
133 global_components_ready_exit = 4;
136 rs_id_1 = nice_agent_add_stream (ragent, 2);
137 g_assert_cmpuint (rs_id_1, >, 0);
138 nice_agent_get_local_credentials(ragent, rs_id_1, &rufrag1, &rpassword1);
140 rs_id_2 = nice_agent_add_stream (ragent, 2);
141 g_assert_cmpuint (rs_id_2, >, 0);
142 nice_agent_get_local_credentials(ragent, rs_id_2, &rufrag2, &rpassword2);
144 nice_agent_set_remote_credentials (ragent, rs_id_2, lufrag, lpassword);
145 nice_agent_set_remote_credentials (lagent, ls_id, rufrag2, rpassword2);
147 g_assert (nice_agent_gather_candidates (lagent, ls_id) == TRUE);
148 g_assert (nice_agent_gather_candidates (ragent, rs_id_2) == TRUE);
149 g_assert (nice_agent_gather_candidates (ragent, rs_id_1) == TRUE);
151 if (USE_SECOND_STREAM) {
152 set_candidates (ragent, rs_id_2, lagent, ls_id, NICE_COMPONENT_TYPE_RTP);
153 set_candidates (ragent, rs_id_2, lagent, ls_id, NICE_COMPONENT_TYPE_RTCP);
154 set_candidates (lagent, ls_id, ragent, rs_id_2, NICE_COMPONENT_TYPE_RTP);
155 set_candidates (lagent, ls_id, ragent, rs_id_2, NICE_COMPONENT_TYPE_RTCP);
157 set_candidates (ragent, rs_id_1, lagent, ls_id, NICE_COMPONENT_TYPE_RTP);
158 set_candidates (ragent, rs_id_1, lagent, ls_id, NICE_COMPONENT_TYPE_RTCP);
159 set_candidates (lagent, ls_id, ragent, rs_id_1, NICE_COMPONENT_TYPE_RTP);
160 set_candidates (lagent, ls_id, ragent, rs_id_1, NICE_COMPONENT_TYPE_RTCP);
163 /* step: attach to mainloop (needed to register the fds) */
164 nice_agent_attach_recv (ragent, rs_id_1, NICE_COMPONENT_TYPE_RTP,
165 g_main_loop_get_context (global_mainloop), cb_nice_recv, NULL);
166 nice_agent_attach_recv (ragent, rs_id_1, NICE_COMPONENT_TYPE_RTCP,
167 g_main_loop_get_context (global_mainloop), cb_nice_recv, NULL);
168 nice_agent_attach_recv (ragent, rs_id_2, NICE_COMPONENT_TYPE_RTP,
169 g_main_loop_get_context (global_mainloop), cb_nice_recv, NULL);
170 nice_agent_attach_recv (ragent, rs_id_2, NICE_COMPONENT_TYPE_RTCP,
171 g_main_loop_get_context (global_mainloop), cb_nice_recv, NULL);
173 rs_id_1 = nice_agent_add_stream (ragent, 2);
174 g_assert_cmpuint (rs_id_1, >, 0);
175 nice_agent_get_local_credentials(ragent, rs_id_1, &rufrag1, &rpassword1);
177 nice_agent_set_remote_credentials (ragent, rs_id_1, lufrag, lpassword);
178 nice_agent_set_remote_credentials (lagent, ls_id, rufrag1, rpassword1);
180 g_assert (nice_agent_gather_candidates (lagent, ls_id) == TRUE);
181 g_assert (nice_agent_gather_candidates (ragent, rs_id_1) == TRUE);
183 /* step: attach to mainloop (needed to register the fds) */
184 nice_agent_attach_recv (ragent, rs_id_1, NICE_COMPONENT_TYPE_RTP,
185 g_main_loop_get_context (global_mainloop), cb_nice_recv, NULL);
186 nice_agent_attach_recv (ragent, rs_id_1, NICE_COMPONENT_TYPE_RTCP,
187 g_main_loop_get_context (global_mainloop), cb_nice_recv, NULL);
189 set_candidates (ragent, rs_id_1, lagent, ls_id, NICE_COMPONENT_TYPE_RTP);
190 set_candidates (ragent, rs_id_1, lagent, ls_id, NICE_COMPONENT_TYPE_RTCP);
191 set_candidates (lagent, ls_id, ragent, rs_id_1, NICE_COMPONENT_TYPE_RTP);
192 set_candidates (lagent, ls_id, ragent, rs_id_1, NICE_COMPONENT_TYPE_RTCP);
195 /* step: run the mainloop until connectivity checks succeed
196 * (see timer_cb() above) */
197 g_main_loop_run (global_mainloop);
205 g_object_unref (lagent);
206 g_object_unref (ragent);
208 g_main_loop_unref (global_mainloop);
209 global_mainloop = NULL;
211 g_source_remove (timer_id);