mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-06 03:25:31 +00:00
sip: origin: do not use hardcoded ports for RTP
This commit is contained in:
parent
6681077886
commit
a53f07dfd3
4 changed files with 22 additions and 4 deletions
|
@ -29,6 +29,7 @@
|
|||
#include "calls-message-source.h"
|
||||
#include "calls-sip-media-manager.h"
|
||||
#include "calls-sip-media-pipeline.h"
|
||||
#include "calls-sip-util.h"
|
||||
#include "calls-call.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
@ -73,6 +74,7 @@ answer (CallsCall *call)
|
|||
{
|
||||
CallsSipCall *self;
|
||||
g_autofree gchar *local_sdp = NULL;
|
||||
guint local_port = get_port_for_rtp ();
|
||||
|
||||
g_assert (CALLS_IS_CALL (call));
|
||||
g_assert (CALLS_IS_SIP_CALL (call));
|
||||
|
@ -87,10 +89,10 @@ answer (CallsCall *call)
|
|||
}
|
||||
|
||||
/* XXX dynamically get free ports */
|
||||
calls_sip_call_setup_local_media (self, 19042, 19043);
|
||||
calls_sip_call_setup_local_media (self, local_port, local_port + 1);
|
||||
|
||||
local_sdp = calls_sip_media_manager_static_capabilities (self->manager,
|
||||
19042,
|
||||
local_port,
|
||||
FALSE);
|
||||
|
||||
g_assert (local_sdp);
|
||||
|
|
|
@ -646,15 +646,16 @@ add_call (CallsSipOrigin *self,
|
|||
CallsSipCall *sip_call;
|
||||
CallsCall *call;
|
||||
g_autofree gchar *local_sdp = NULL;
|
||||
guint local_port = get_port_for_rtp ();
|
||||
|
||||
sip_call = calls_sip_call_new (address, inbound, handle);
|
||||
g_assert (sip_call != NULL);
|
||||
|
||||
/* XXX dynamically get/probe free ports */
|
||||
calls_sip_call_setup_local_media (sip_call, 19042, 19043);
|
||||
calls_sip_call_setup_local_media (sip_call, local_port, local_port + 1);
|
||||
|
||||
local_sdp = calls_sip_media_manager_static_capabilities (self->media_manager,
|
||||
19042,
|
||||
local_port,
|
||||
check_sips (address));
|
||||
|
||||
g_assert (local_sdp);
|
||||
|
|
|
@ -53,3 +53,17 @@ protocol_is_valid (const gchar *protocol)
|
|||
g_strcmp0 (protocol, "TCP") == 0 ||
|
||||
g_strcmp0 (protocol, "TLS") == 0;
|
||||
}
|
||||
|
||||
#define RTP_PORT_MIN 20000
|
||||
#define RTP_PORT_MAX 65534
|
||||
guint
|
||||
get_port_for_rtp (void)
|
||||
{
|
||||
const guint rand_range = RTP_PORT_MAX - RTP_PORT_MIN;
|
||||
guint rand = (g_random_int () % rand_range) + RTP_PORT_MIN;
|
||||
|
||||
/* RTP ports must be even */
|
||||
return rand % 2 == 0 ? rand : rand + 1;
|
||||
}
|
||||
#undef RTP_PORT_MIN
|
||||
#undef RTP_PORT_MAX
|
||||
|
|
|
@ -82,3 +82,4 @@ typedef enum
|
|||
gboolean check_sips (const gchar *addr);
|
||||
const gchar *get_protocol_prefix (const gchar *protocol);
|
||||
gboolean protocol_is_valid (const gchar *protocol);
|
||||
guint get_port_for_rtp (void);
|
||||
|
|
Loading…
Reference in a new issue