diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-03-31 19:08:37 +0200 |
---|---|---|
committer | Wim Taymans <wim@metal.(none)> | 2009-03-31 19:08:37 +0200 |
commit | b037369d5b4547c3dd2d501c3751e5990d01a4f9 (patch) | |
tree | ca8f9a92731cb2f866972ac688355616b646499e | |
parent | 605ded52927528bada4a79844ca8d2316aae98eb (diff) |
rtspsrc: add proxy support
-rw-r--r-- | gst/rtsp/gstrtspsrc.c | 85 | ||||
-rw-r--r-- | gst/rtsp/gstrtspsrc.h | 4 |
2 files changed, 89 insertions, 0 deletions
diff --git a/gst/rtsp/gstrtspsrc.c b/gst/rtsp/gstrtspsrc.c index 64b501cb9..667211a33 100644 --- a/gst/rtsp/gstrtspsrc.c +++ b/gst/rtsp/gstrtspsrc.c | |||
@@ -148,6 +148,7 @@ enum | |||
148 | #define DEFAULT_CONNECTION_SPEED 0 | 148 | #define DEFAULT_CONNECTION_SPEED 0 |
149 | #define DEFAULT_NAT_METHOD GST_RTSP_NAT_DUMMY | 149 | #define DEFAULT_NAT_METHOD GST_RTSP_NAT_DUMMY |
150 | #define DEFAULT_DO_RTCP TRUE | 150 | #define DEFAULT_DO_RTCP TRUE |
151 | #define DEFAULT_PROXY NULL | ||
151 | 152 | ||
152 | enum | 153 | enum |
153 | { | 154 | { |
@@ -162,6 +163,7 @@ enum | |||
162 | PROP_CONNECTION_SPEED, | 163 | PROP_CONNECTION_SPEED, |
163 | PROP_NAT_METHOD, | 164 | PROP_NAT_METHOD, |
164 | PROP_DO_RTCP, | 165 | PROP_DO_RTCP, |
166 | PROP_PROXY, | ||
165 | PROP_LAST | 167 | PROP_LAST |
166 | }; | 168 | }; |
167 | 169 | ||
@@ -352,6 +354,19 @@ gst_rtspsrc_class_init (GstRTSPSrcClass * klass) | |||
352 | "Send RTCP packets, disable for old incompatible server.", | 354 | "Send RTCP packets, disable for old incompatible server.", |
353 | DEFAULT_DO_RTCP, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); | 355 | DEFAULT_DO_RTCP, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); |
354 | 356 | ||
357 | /** | ||
358 | * GstRTSPSrc::proxy | ||
359 | * | ||
360 | * Set the proxy parameters. This has to be a string of the format | ||
361 | * [user:passwd@]host[:port]. | ||
362 | * | ||
363 | * Since: 0.10.15 | ||
364 | */ | ||
365 | g_object_class_install_property (gobject_class, PROP_PROXY, | ||
366 | g_param_spec_string ("proxy", "Proxy", | ||
367 | "Proxy settings for HTTP tunneling. Format: [user:passwd@]host[:port]", | ||
368 | DEFAULT_PROXY, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); | ||
369 | |||
355 | gstelement_class->change_state = gst_rtspsrc_change_state; | 370 | gstelement_class->change_state = gst_rtspsrc_change_state; |
356 | 371 | ||
357 | gstbin_class->handle_message = gst_rtspsrc_handle_message; | 372 | gstbin_class->handle_message = gst_rtspsrc_handle_message; |
@@ -423,6 +438,53 @@ gst_rtspsrc_finalize (GObject * object) | |||
423 | G_OBJECT_CLASS (parent_class)->finalize (object); | 438 | G_OBJECT_CLASS (parent_class)->finalize (object); |
424 | } | 439 | } |
425 | 440 | ||
441 | /* a proxy string of the format [user:passwd@]host[:port] */ | ||
442 | static gboolean | ||
443 | gst_rtspsrc_set_proxy (GstRTSPSrc * rtsp, const gchar * proxy) | ||
444 | { | ||
445 | gchar *p, *at, *col; | ||
446 | |||
447 | g_free (rtsp->proxy_user); | ||
448 | rtsp->proxy_user = NULL; | ||
449 | g_free (rtsp->proxy_passwd); | ||
450 | rtsp->proxy_passwd = NULL; | ||
451 | g_free (rtsp->proxy_host); | ||
452 | rtsp->proxy_host = NULL; | ||
453 | rtsp->proxy_port = 0; | ||
454 | |||
455 | p = (gchar *) proxy; | ||
456 | |||
457 | if (p == NULL) | ||
458 | return TRUE; | ||
459 | |||
460 | at = strchr (p, '@'); | ||
461 | if (at) { | ||
462 | /* look for user:passwd */ | ||
463 | col = strchr (proxy, ':'); | ||
464 | if (col == NULL || col > at) | ||
465 | return FALSE; | ||
466 | |||
467 | rtsp->proxy_user = g_strndup (p, col - p); | ||
468 | col++; | ||
469 | rtsp->proxy_passwd = g_strndup (col, at - col); | ||
470 | |||
471 | /* move to host */ | ||
472 | p = at + 1; | ||
473 | } | ||
474 | col = strchr (p, ':'); | ||
475 | |||
476 | if (col) { | ||
477 | /* everything before the colon is the hostname */ | ||
478 | rtsp->proxy_host = g_strndup (p, col - p); | ||
479 | p = col + 1; | ||
480 | rtsp->proxy_port = strtoul (p, (char **) &p, 10); | ||
481 | } else { | ||
482 | rtsp->proxy_host = g_strdup (p); | ||
483 | rtsp->proxy_port = 8080; | ||
484 | } | ||
485 | return TRUE; | ||
486 | } | ||
487 | |||
426 | static void | 488 | static void |
427 | gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value, | 489 | gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value, |
428 | GParamSpec * pspec) | 490 | GParamSpec * pspec) |
@@ -473,6 +535,9 @@ gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value, | |||
473 | case PROP_DO_RTCP: | 535 | case PROP_DO_RTCP: |
474 | rtspsrc->do_rtcp = g_value_get_boolean (value); | 536 | rtspsrc->do_rtcp = g_value_get_boolean (value); |
475 | break; | 537 | break; |
538 | case PROP_PROXY: | ||
539 | gst_rtspsrc_set_proxy (rtspsrc, g_value_get_string (value)); | ||
540 | break; | ||
476 | default: | 541 | default: |
477 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 542 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
478 | break; | 543 | break; |
@@ -524,6 +589,19 @@ gst_rtspsrc_get_property (GObject * object, guint prop_id, GValue * value, | |||
524 | case PROP_DO_RTCP: | 589 | case PROP_DO_RTCP: |
525 | g_value_set_boolean (value, rtspsrc->do_rtcp); | 590 | g_value_set_boolean (value, rtspsrc->do_rtcp); |
526 | break; | 591 | break; |
592 | case PROP_PROXY: | ||
593 | { | ||
594 | gchar *str; | ||
595 | |||
596 | if (rtspsrc->proxy_host) { | ||
597 | str = | ||
598 | g_strdup_printf ("%s:%d", rtspsrc->proxy_host, rtspsrc->proxy_port); | ||
599 | } else { | ||
600 | str = NULL; | ||
601 | } | ||
602 | g_value_take_string (value, str); | ||
603 | break; | ||
604 | } | ||
527 | default: | 605 | default: |
528 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 606 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
529 | break; | 607 | break; |
@@ -4321,6 +4399,13 @@ restart: | |||
4321 | if (url->transports & GST_RTSP_LOWER_TRANS_HTTP) | 4399 | if (url->transports & GST_RTSP_LOWER_TRANS_HTTP) |
4322 | gst_rtsp_connection_set_tunneled (src->connection, TRUE); | 4400 | gst_rtsp_connection_set_tunneled (src->connection, TRUE); |
4323 | 4401 | ||
4402 | if (src->proxy_host) { | ||
4403 | GST_DEBUG_OBJECT (src, "setting proxy %s:%d", src->proxy_host, | ||
4404 | src->proxy_port); | ||
4405 | gst_rtsp_connection_set_proxy (src->connection, src->proxy_host, | ||
4406 | src->proxy_port); | ||
4407 | } | ||
4408 | |||
4324 | /* connect */ | 4409 | /* connect */ |
4325 | GST_DEBUG_OBJECT (src, "connecting (%s)...", src->req_location); | 4410 | GST_DEBUG_OBJECT (src, "connecting (%s)...", src->req_location); |
4326 | if ((res = | 4411 | if ((res = |
diff --git a/gst/rtsp/gstrtspsrc.h b/gst/rtsp/gstrtspsrc.h index c90e671ae..2e41c2749 100644 --- a/gst/rtsp/gstrtspsrc.h +++ b/gst/rtsp/gstrtspsrc.h | |||
@@ -188,6 +188,10 @@ struct _GstRTSPSrc { | |||
188 | guint connection_speed; | 188 | guint connection_speed; |
189 | GstRTSPNatMethod nat_method; | 189 | GstRTSPNatMethod nat_method; |
190 | gboolean do_rtcp; | 190 | gboolean do_rtcp; |
191 | gchar *proxy_host; | ||
192 | guint proxy_port; | ||
193 | gchar *proxy_user; | ||
194 | gchar *proxy_passwd; | ||
191 | 195 | ||
192 | /* state */ | 196 | /* state */ |
193 | GstRTSPState state; | 197 | GstRTSPState state; |