[asterisk-commits] file: branch file/rtp_engine r129222 - in /team/file/rtp_engine: apps/ channe...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 8 17:06:17 CDT 2008
Author: file
Date: Tue Jul 8 17:06:17 2008
New Revision: 129222
URL: http://svn.digium.com/view/asterisk?view=rev&rev=129222
Log:
Add some debugging and finish up things so I have very basic RTP working, along with payload negotiation.
Modified:
team/file/rtp_engine/apps/app_dial.c
team/file/rtp_engine/channels/chan_sip.c
team/file/rtp_engine/include/asterisk/rtp_engine.h
team/file/rtp_engine/main/rtp_engine.c
team/file/rtp_engine/res/res_rtp_asterisk.c
Modified: team/file/rtp_engine/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/apps/app_dial.c?view=diff&rev=129222&r1=129221&r2=129222
==============================================================================
--- team/file/rtp_engine/apps/app_dial.c (original)
+++ team/file/rtp_engine/apps/app_dial.c Tue Jul 8 17:06:17 2008
@@ -518,7 +518,6 @@
char *new_cid_num, *new_cid_name;
struct ast_channel *src;
- ast_rtp_make_compatible(c, in, single);
if (ast_test_flag64(o, OPT_FORCECLID)) {
new_cid_num = ast_strdup(S_OR(in->macroexten, in->exten));
new_cid_name = NULL; /* XXX no name ? */
@@ -1480,9 +1479,6 @@
continue;
}
pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", numsubst);
-
- /* Setup outgoing SDP to match incoming one */
- ast_rtp_make_compatible(tc, chan, !outgoing && !rest);
/* Inherit specially named variables from parent channel */
ast_channel_inherit_variables(chan, tc);
Modified: team/file/rtp_engine/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/channels/chan_sip.c?view=diff&rev=129222&r1=129221&r2=129222
==============================================================================
--- team/file/rtp_engine/channels/chan_sip.c (original)
+++ team/file/rtp_engine/channels/chan_sip.c Tue Jul 8 17:06:17 2008
@@ -5931,16 +5931,15 @@
p->ocseq = INITIAL_CSEQ;
if (sip_methods[intended_method].need_rtp) {
- //p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
- p->rtp = ast_rtp_instance_new(NULL, NULL);
+ p->rtp = ast_rtp_instance_new(NULL, NULL, sched, &bindaddr);
ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1);
/* If the global videosupport flag is on, we always create a RTP interface for video */
if (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT)) {
- p->vrtp = ast_rtp_instance_new(NULL, NULL);
+ p->vrtp = ast_rtp_instance_new(NULL, NULL, sched, &bindaddr);
ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, 1);
}
if (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT)) {
- p->trtp = ast_rtp_instance_new(NULL, NULL);
+ p->trtp = ast_rtp_instance_new(NULL, NULL, sched, &bindaddr);
ast_rtp_instance_set_prop(p->trtp, AST_RTP_PROPERTY_RTCP, 1);
}
if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT))
Modified: team/file/rtp_engine/include/asterisk/rtp_engine.h
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/include/asterisk/rtp_engine.h?view=diff&rev=129222&r1=129221&r2=129222
==============================================================================
--- team/file/rtp_engine/include/asterisk/rtp_engine.h (original)
+++ team/file/rtp_engine/include/asterisk/rtp_engine.h Tue Jul 8 17:06:17 2008
@@ -76,7 +76,7 @@
struct ast_rtp_engine {
const char *name; /*!< Name of the RTP engine */
struct ast_module *mod; /*!< Module this RTP engine belongs to */
- int (*new)(struct ast_rtp_instance *instance); /*!< Callback for creating an RTP instance */
+ int (*new)(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin); /*!< Callback for creating an RTP instance */
int (*destroy)(struct ast_rtp_instance *instance); /*!< Callback for destroying an RTP instance */
int (*write)(struct ast_rtp_instance *instance, struct ast_frame *frame); /*!< Callback for writing a frame out */
void (*stop)(struct ast_rtp_instance *instance); /*!< Callback for stopping the RTP session */
@@ -142,11 +142,13 @@
*
* \param engine_name Name of the engine to use for the RTP instance
* \param glue The glue to use when bridging
+ * \param sched Scheduler context that the RTP engine may want to use
+ * \param sin Address we want to bind to
*
* \retval non-NULL success
* \retval NULL failure
*/
-struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct ast_rtp_glue *glue);
+struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct ast_rtp_glue *glue, struct sched_context *sched, struct sockaddr_in *sin);
/*! \brief Destroy an RTP instance
*
Modified: team/file/rtp_engine/main/rtp_engine.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/main/rtp_engine.c?view=diff&rev=129222&r1=129221&r2=129222
==============================================================================
--- team/file/rtp_engine/main/rtp_engine.c (original)
+++ team/file/rtp_engine/main/rtp_engine.c Tue Jul 8 17:06:17 2008
@@ -180,7 +180,7 @@
return current_engine ? 0 : -1;
}
-struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct ast_rtp_glue *glue)
+struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct ast_rtp_glue *glue, struct sched_context *sched, struct sockaddr_in *sin)
{
struct ast_rtp_instance *instance = NULL;
struct ast_rtp_engine *engine = NULL;
@@ -216,14 +216,20 @@
}
instance->engine = engine;
instance->glue = glue;
+ memcpy(&instance->local_address, sin, sizeof(instance->local_address));
+
+ ast_debug(1, "Using engine '%s' for RTP instance '%p'\n", engine->name, instance);
/* And pass it off to the engine to setup */
- if (instance->engine->new(instance)) {
+ if (instance->engine->new(instance, sched, sin)) {
+ ast_debug(1, "Engine '%s' failed to setup RTP instance '%p'\n", engine->name, instance);
ast_module_unref(engine->mod);
ast_free(instance);
return NULL;
}
+ ast_debug(1, "RTP instance '%p' is setup and ready to go\n", instance);
+
return instance;
}
@@ -231,6 +237,7 @@
{
/* Pass us off to the engine to destroy */
if (instance->engine->destroy(instance)) {
+ ast_debug(1, "Engine '%s' failed to destroy RTP instance '%p'\n", instance->engine->name, instance);
return -1;
}
@@ -240,6 +247,8 @@
/* and do the hand jive */
ast_free(instance);
+ ast_debug(1, "Destroyed RTP instance '%p'\n", instance);
+
return 0;
}
@@ -255,6 +264,8 @@
int ast_rtp_instance_set_remote_address(struct ast_rtp_instance *instance, struct sockaddr_in *address)
{
+ memcpy(&instance->remote_address, address, sizeof(instance->remote_address));
+
return -1;
}
Modified: team/file/rtp_engine/res/res_rtp_asterisk.c
URL: http://svn.digium.com/view/asterisk/team/file/rtp_engine/res/res_rtp_asterisk.c?view=diff&rev=129222&r1=129221&r2=129222
==============================================================================
--- team/file/rtp_engine/res/res_rtp_asterisk.c (original)
+++ team/file/rtp_engine/res/res_rtp_asterisk.c Tue Jul 8 17:06:17 2008
@@ -218,7 +218,7 @@
};
/* Forward Declarations */
-static int ast_rtp_new(struct ast_rtp_instance *instance);
+static int ast_rtp_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin);
static int ast_rtp_destroy(struct ast_rtp_instance *instance);
static int ast_rtp_dtmf_begin(struct ast_rtp_instance *instance, char digit);
static int ast_rtp_dtmf_end(struct ast_rtp_instance *instance, char digit);
@@ -292,22 +292,55 @@
return sock;
}
-static int ast_rtp_new(struct ast_rtp_instance *instance)
+static int ast_rtp_new(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin)
{
struct ast_rtp *rtp = NULL;
+ int x, startplace;
/* Create a new RTP structure to hold all of our data */
if (!(rtp = ast_calloc(1, sizeof(*rtp)))) {
return -1;
}
+ /* Set default parameters on the newly created RTP structure */
+ rtp->ssrc = ast_random();
+ rtp->seqno = ast_random() & 0xffff;
+ rtp->strict_rtp_state = (strictrtp ? STRICT_RTP_LEARN : STRICT_RTP_OPEN);
+
/* Create a new socket for us to listen on and use */
if ((rtp->s = create_new_socket("RTP")) < 0) {
+ ast_debug(1, "Failed to create a new socket for RTP instance '%p'\n", instance);
ast_free(rtp);
return -1;
}
/* Now actually find a free RTP port to use */
+ x = (ast_random() % (rtpend-rtpstart)) + rtpstart;
+ x = x & ~1;
+ startplace = x;
+
+ for (;;) {
+ instance->local_address.sin_port = htons(x);
+ /* Try to bind, this will tell us whether the port is available or not */
+ if (!bind(rtp->s, (struct sockaddr*)&instance->local_address, sizeof(instance->local_address))) {
+ ast_debug(1, "Allocated port %d for RTP instance '%p'\n", x, instance);
+ break;
+ }
+
+ x += 2;
+ if (x > rtpend) {
+ x = (rtpstart + 1) & ~1;
+ }
+
+ /* See if we ran out of ports or if the bind actually failed because of something other than the address being in use */
+ if (x == startplace || errno != EADDRINUSE) {
+ ast_log(LOG_ERROR, "Oh dear... we couldn't allocate a port for RTP instance '%p'\n", instance);
+ return -1;
+ }
+ }
+
+ /* Record any information we may need */
+ rtp->sched = sched;
/* Associate the RTP structure with the RTP instance and be done */
instance->data = rtp;
@@ -636,11 +669,13 @@
/* If we don't actually know the remote address don't even bother doing anything */
if (!instance->remote_address.sin_addr.s_addr) {
+ ast_debug(1, "No remote address on RTP instance '%p' so dropping frame\n", instance);
return -1;
}
/* If there is no data length we can't very well send the packet */
if (!frame->datalen) {
+ ast_debug(1, "Received frame with no data for RTP instance '%p' so dropping frame\n", instance);
return -1;
}
More information about the asterisk-commits
mailing list