comparison libpurple/media/media.c @ 29566:f600903f7811

Transfer creating Farsight 2 streams to the Fs2 media backend.
author maiku@pidgin.im
date Mon, 26 Oct 2009 21:35:11 +0000
parents eef5ec04a5bf
children 983af0970bb2
comparison
equal deleted inserted replaced
29565:eef5ec04a5bf 29566:f600903f7811
1350 FsParticipant *participant = NULL; 1350 FsParticipant *participant = NULL;
1351 PurpleMediaStream *stream = NULL; 1351 PurpleMediaStream *stream = NULL;
1352 FsMediaType media_type = purple_media_to_fs_media_type(type); 1352 FsMediaType media_type = purple_media_to_fs_media_type(type);
1353 FsStreamDirection type_direction = 1353 FsStreamDirection type_direction =
1354 purple_media_to_fs_stream_direction(type); 1354 purple_media_to_fs_stream_direction(type);
1355 gboolean is_nice = !strcmp(transmitter, "nice");
1356 1355
1357 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE); 1356 g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE);
1358 1357
1359 if (media->priv->gst_bus_handler_id == 0) { 1358 if (media->priv->gst_bus_handler_id == 0) {
1360 GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE( 1359 GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(
1430 PURPLE_MEDIA_BACKEND_FS2(media->priv->backend), who); 1429 PURPLE_MEDIA_BACKEND_FS2(media->priv->backend), who);
1431 1430
1432 stream = purple_media_get_stream(media, sess_id, who); 1431 stream = purple_media_get_stream(media, sess_id, who);
1433 1432
1434 if (!stream) { 1433 if (!stream) {
1435 GError *err = NULL;
1436 FsStream *fsstream = NULL; 1434 FsStream *fsstream = NULL;
1437 const gchar *stun_ip = purple_network_get_stun_ip(); 1435
1438 const gchar *turn_ip = purple_network_get_turn_ip(); 1436 fsstream = purple_media_backend_fs2_get_stream(
1439 1437 PURPLE_MEDIA_BACKEND_FS2(
1440 if (stun_ip || turn_ip) { 1438 media->priv->backend), sess_id, who);
1441 guint new_num_params =
1442 (stun_ip && is_nice) && turn_ip ?
1443 num_params + 2 : num_params + 1;
1444 guint next_param_index = num_params;
1445 GParameter *param = g_new0(GParameter, new_num_params);
1446 memcpy(param, params, sizeof(GParameter) * num_params);
1447
1448 if (stun_ip) {
1449 purple_debug_info("media",
1450 "setting property stun-ip on new stream: %s\n", stun_ip);
1451
1452 param[next_param_index].name = "stun-ip";
1453 g_value_init(&param[next_param_index].value, G_TYPE_STRING);
1454 g_value_set_string(&param[next_param_index].value, stun_ip);
1455 next_param_index++;
1456 }
1457
1458 if (turn_ip && is_nice) {
1459 GValueArray *relay_info = g_value_array_new(0);
1460 GValue value;
1461 gint turn_port =
1462 purple_prefs_get_int("/purple/network/turn_port");
1463 const gchar *username =
1464 purple_prefs_get_string("/purple/network/turn_username");
1465 const gchar *password =
1466 purple_prefs_get_string("/purple/network/turn_password");
1467 GstStructure *turn_setup = gst_structure_new("relay-info",
1468 "ip", G_TYPE_STRING, turn_ip,
1469 "port", G_TYPE_UINT, turn_port,
1470 "username", G_TYPE_STRING, username,
1471 "password", G_TYPE_STRING, password,
1472 NULL);
1473
1474 if (turn_setup) {
1475 memset(&value, 0, sizeof(GValue));
1476 g_value_init(&value, GST_TYPE_STRUCTURE);
1477 gst_value_set_structure(&value, turn_setup);
1478 relay_info = g_value_array_append(relay_info, &value);
1479 gst_structure_free(turn_setup);
1480
1481 purple_debug_info("media",
1482 "setting property relay-info on new stream\n");
1483 param[next_param_index].name = "relay-info";
1484 g_value_init(&param[next_param_index].value,
1485 G_TYPE_VALUE_ARRAY);
1486 g_value_set_boxed(&param[next_param_index].value,
1487 relay_info);
1488 g_value_array_free(relay_info);
1489 } else {
1490 purple_debug_error("media", "Error relay info");
1491 purple_media_remove_session(media, session);
1492 g_free(session);
1493 return FALSE;
1494 }
1495 }
1496
1497 fsstream = fs_session_new_stream(session->session,
1498 participant, type_direction &
1499 FS_DIRECTION_RECV, transmitter,
1500 new_num_params, param, &err);
1501 g_free(param);
1502 } else {
1503 fsstream = fs_session_new_stream(session->session,
1504 participant, type_direction &
1505 FS_DIRECTION_RECV, transmitter,
1506 num_params, params, &err);
1507 }
1508
1509 if (fsstream == NULL) {
1510 purple_debug_error("media",
1511 "Error creating stream: %s\n",
1512 err && err->message ?
1513 err->message : "NULL");
1514 if (err)
1515 g_error_free(err);
1516 purple_media_remove_session(media, session);
1517 g_free(session);
1518 return FALSE;
1519 }
1520 1439
1521 stream = purple_media_insert_stream(session, who, fsstream); 1440 stream = purple_media_insert_stream(session, who, fsstream);
1522 stream->initiator = initiator; 1441 stream->initiator = initiator;
1523 1442
1524 /* callback for source pad added (new stream source ready) */ 1443 /* callback for source pad added (new stream source ready) */