[asterisk-commits] file: branch file/gulp_fax r394459 - in /team/file/gulp_fax: channels/ includ...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 16 12:10:11 CDT 2013
Author: file
Date: Tue Jul 16 12:10:09 2013
New Revision: 394459
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394459
Log:
Add a callback to ast_sip_session_refresh which allows manipulation of the SDP.
This is used in the T.38 code to remove all streams except T.38 and move it to the front.
Modified:
team/file/gulp_fax/channels/chan_gulp.c
team/file/gulp_fax/include/asterisk/res_sip_session.h
team/file/gulp_fax/res/res_sip_session.c
team/file/gulp_fax/res/res_sip_t38.c
Modified: team/file/gulp_fax/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/file/gulp_fax/channels/chan_gulp.c?view=diff&rev=394459&r1=394458&r2=394459
==============================================================================
--- team/file/gulp_fax/channels/chan_gulp.c (original)
+++ team/file/gulp_fax/channels/chan_gulp.c Tue Jul 16 12:10:09 2013
@@ -422,7 +422,7 @@
{
RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
- return ast_sip_session_refresh(session, NULL, NULL, session->endpoint->direct_media_method, 1);
+ return ast_sip_session_refresh(session, NULL, NULL, NULL, session->endpoint->direct_media_method, 1);
}
static struct ast_datastore_info direct_media_mitigation_info = { };
@@ -1062,7 +1062,7 @@
method = AST_SIP_SESSION_REFRESH_METHOD_UPDATE;
}
- ast_sip_session_refresh(session, NULL, NULL, method, 0);
+ ast_sip_session_refresh(session, NULL, NULL, NULL, method, 0);
}
return 0;
Modified: team/file/gulp_fax/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/file/gulp_fax/include/asterisk/res_sip_session.h?view=diff&rev=394459&r1=394458&r2=394459
==============================================================================
--- team/file/gulp_fax/include/asterisk/res_sip_session.h (original)
+++ team/file/gulp_fax/include/asterisk/res_sip_session.h Tue Jul 16 12:10:09 2013
@@ -136,6 +136,7 @@
typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);
typedef int (*ast_sip_session_response_cb)(struct ast_sip_session *session, pjsip_rx_data *rdata);
+typedef int (*ast_sip_session_sdp_creation_cb)(struct ast_sip_session *session, pjmedia_sdp_session *sdp);
enum ast_sip_session_supplement_priority {
/*! Top priority. Supplements with this priority are those that need to run before any others */
@@ -466,6 +467,7 @@
*
* \param session The session on which the reinvite will be sent
* \param on_request_creation Callback called when request is created
+ * \param on_sdp_creation Callback called when SDP is created
* \param on_response Callback called when response for request is received
* \param method The method that should be used when constructing the session refresh
* \param generate_new_sdp Boolean to indicate if a new SDP should be created
@@ -474,6 +476,7 @@
*/
int ast_sip_session_refresh(struct ast_sip_session *session,
ast_sip_session_request_creation_cb on_request_creation,
+ ast_sip_session_sdp_creation_cb on_sdp_creation,
ast_sip_session_response_cb on_response,
enum ast_sip_session_refresh_method method,
int generate_new_sdp);
Modified: team/file/gulp_fax/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/file/gulp_fax/res/res_sip_session.c?view=diff&rev=394459&r1=394458&r2=394459
==============================================================================
--- team/file/gulp_fax/res/res_sip_session.c (original)
+++ team/file/gulp_fax/res/res_sip_session.c Tue Jul 16 12:10:09 2013
@@ -623,6 +623,8 @@
char method[15];
/*! Callback to call when the delayed request is created. */
ast_sip_session_request_creation_cb on_request_creation;
+ /*! Callback to call when the delayed request SDP is created */
+ ast_sip_session_sdp_creation_cb on_sdp_creation;
/*! Callback to call when the delayed request receives a response */
ast_sip_session_response_cb on_response;
/*! Request to send */
@@ -632,6 +634,7 @@
static struct ast_sip_session_delayed_request *delayed_request_alloc(const char *method,
ast_sip_session_request_creation_cb on_request_creation,
+ ast_sip_session_sdp_creation_cb on_sdp_creation,
ast_sip_session_response_cb on_response,
pjsip_tx_data *tdata)
{
@@ -641,6 +644,7 @@
}
ast_copy_string(delay->method, method, sizeof(delay->method));
delay->on_request_creation = on_request_creation;
+ delay->on_sdp_creation = on_sdp_creation;
delay->on_response = on_response;
delay->tdata = tdata;
return delay;
@@ -657,10 +661,10 @@
if (!strcmp(delay->method, "INVITE")) {
ast_sip_session_refresh(session, delay->on_request_creation,
- delay->on_response, AST_SIP_SESSION_REFRESH_METHOD_INVITE, 1);
+ delay->on_sdp_creation, delay->on_response, AST_SIP_SESSION_REFRESH_METHOD_INVITE, 1);
} else if (!strcmp(delay->method, "UPDATE")) {
ast_sip_session_refresh(session, delay->on_request_creation,
- delay->on_response, AST_SIP_SESSION_REFRESH_METHOD_UPDATE, 1);
+ delay->on_sdp_creation, delay->on_response, AST_SIP_SESSION_REFRESH_METHOD_UPDATE, 1);
} else {
ast_log(LOG_WARNING, "Unexpected delayed %s request with no existing request structure\n", delay->method);
return -1;
@@ -696,10 +700,11 @@
}
static int delay_request(struct ast_sip_session *session, ast_sip_session_request_creation_cb on_request,
- ast_sip_session_response_cb on_response, const char *method, pjsip_tx_data *tdata)
+ ast_sip_session_sdp_creation_cb on_sdp_creation, ast_sip_session_response_cb on_response,
+ const char *method, pjsip_tx_data *tdata)
{
struct ast_sip_session_delayed_request *delay = delayed_request_alloc(method,
- on_request, on_response, tdata);
+ on_request, on_sdp_creation, on_response, tdata);
if (!delay) {
return -1;
@@ -723,7 +728,9 @@
}
int ast_sip_session_refresh(struct ast_sip_session *session,
- ast_sip_session_request_creation_cb on_request_creation, ast_sip_session_response_cb on_response,
+ ast_sip_session_request_creation_cb on_request_creation,
+ ast_sip_session_sdp_creation_cb on_sdp_creation,
+ ast_sip_session_response_cb on_response,
enum ast_sip_session_refresh_method method, int generate_new_sdp)
{
pjsip_inv_session *inv_session = session->inv_session;
@@ -741,7 +748,7 @@
/* We can't send a reinvite yet, so delay it */
ast_debug(3, "Delaying sending reinvite to %s because of outstanding transaction...\n",
ast_sorcery_object_get_id(session->endpoint));
- return delay_request(session, on_request_creation, on_response, "INVITE", NULL);
+ return delay_request(session, on_request_creation, on_sdp_creation, on_response, "INVITE", NULL);
}
if (generate_new_sdp) {
@@ -749,6 +756,11 @@
if (!new_sdp) {
ast_log(LOG_ERROR, "Failed to generate session refresh SDP. Not sending session refresh\n");
return -1;
+ }
+ if (on_sdp_creation) {
+ if (on_sdp_creation(session, new_sdp)) {
+ return -1;
+ }
}
}
@@ -1584,7 +1596,7 @@
static void reschedule_reinvite(struct ast_sip_session *session, ast_sip_session_response_cb on_response, pjsip_tx_data *tdata)
{
struct ast_sip_session_delayed_request *delay = delayed_request_alloc("INVITE",
- NULL, on_response, tdata);
+ NULL, NULL, on_response, tdata);
pjsip_inv_session *inv = session->inv_session;
struct reschedule_reinvite_data *rrd = reschedule_reinvite_data_alloc(session, delay);
pj_time_val tv;
Modified: team/file/gulp_fax/res/res_sip_t38.c
URL: http://svnview.digium.com/svn/asterisk/team/file/gulp_fax/res/res_sip_t38.c?view=diff&rev=394459&r1=394458&r2=394459
==============================================================================
--- team/file/gulp_fax/res/res_sip_t38.c (original)
+++ team/file/gulp_fax/res/res_sip_t38.c Tue Jul 16 12:10:09 2013
@@ -270,6 +270,25 @@
ast_channel_set_fd(session->channel, 5, ast_udptl_fd(session_media->udptl));
ast_udptl_set_error_correction_scheme(session_media->udptl, session->endpoint->t38udptl_ec);
ast_udptl_setnat(session_media->udptl, session->endpoint->t38udptl_nat);
+
+ return 0;
+}
+
+/*! \brief Callback for when T.38 reinvite SDP is created */
+static int t38_reinvite_sdp_cb(struct ast_sip_session *session, pjmedia_sdp_session *sdp)
+{
+ int stream;
+
+ /* Move the image media stream to the front and have it as the only stream, pjmedia will fill in
+ * dummy streams for the rest
+ */
+ for (stream = 0; stream < sdp->media_count++; ++stream) {
+ if (!pj_strcmp2(&sdp->media[stream]->desc.media, "image")) {
+ sdp->media[0] = sdp->media[stream];
+ sdp->media_count = 1;
+ break;
+ }
+ }
return 0;
}
@@ -322,9 +341,8 @@
}
state->our_parms = *parameters;
ast_udptl_set_local_max_ifp(session_media->udptl, state->our_parms.max_ifp);
- /* XXX Need to suppress other streams temporarily */
t38_change_state(data->session, session_media, state, T38_LOCAL_REINVITE);
- ast_sip_session_refresh(data->session, NULL, NULL, AST_SIP_SESSION_REFRESH_METHOD_INVITE, 1);
+ ast_sip_session_refresh(data->session, NULL, t38_reinvite_sdp_cb, NULL, AST_SIP_SESSION_REFRESH_METHOD_INVITE, 1);
}
break;
case AST_T38_TERMINATED:
@@ -334,9 +352,8 @@
t38_change_state(data->session, session_media, state, T38_REJECTED);
ast_sip_session_resume_reinvite(data->session);
} else if (data->session->t38state == T38_ENABLED) {
- /* XXX Need to unsupress other streams */
t38_change_state(data->session, session_media, state, T38_DISABLED);
- ast_sip_session_refresh(data->session, NULL, NULL, AST_SIP_SESSION_REFRESH_METHOD_INVITE, 1);
+ ast_sip_session_refresh(data->session, NULL, NULL, NULL, AST_SIP_SESSION_REFRESH_METHOD_INVITE, 1);
}
break;
case AST_T38_REQUEST_PARMS: { /* Application wants remote's parameters re-sent */
@@ -472,24 +489,11 @@
.outgoing_request = t38_outgoing_invite_request,
};
-/*! \brief Function which defers an incoming media stream */
-static int defer_incoming_sdp_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media,
- const struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_media *stream)
-{
- struct t38_state *state;
+/*! \brief Parse a T.38 image stream and store the attribute information */
+static void t38_interpret_sdp(struct t38_state *state, struct ast_sip_session *session, struct ast_sip_session_media *session_media,
+ const struct pjmedia_sdp_media *stream)
+{
unsigned int attr_i;
-
- if (!session->endpoint->t38udptl) {
- return 1;
- }
-
- if (t38_initialize_session(session, session_media)) {
- return 1;
- }
-
- if (!(state = t38_state_get_or_alloc(session))) {
- return 1;
- }
for (attr_i = 0; attr_i < stream->attr_count; attr_i++) {
pjmedia_sdp_attr *attr = stream->attr[attr_i];
@@ -548,6 +552,27 @@
}
}
+}
+
+/*! \brief Function which defers an incoming media stream */
+static int defer_incoming_sdp_stream(struct ast_sip_session *session, struct ast_sip_session_media *session_media,
+ const struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_media *stream)
+{
+ struct t38_state *state;
+
+ if (!session->endpoint->t38udptl) {
+ return 1;
+ }
+
+ if (t38_initialize_session(session, session_media)) {
+ return 1;
+ }
+
+ if (!(state = t38_state_get_or_alloc(session))) {
+ return 1;
+ }
+
+ t38_interpret_sdp(state, session, session_media, stream);
/* If they are initiating the re-invite we need to defer responding until later */
if (session->t38state == T38_DISABLED) {
@@ -555,7 +580,7 @@
return -1;
}
- return 1;
+ return 0;
}
/*! \brief Function which negotiates an incoming media stream */
@@ -589,6 +614,11 @@
if (t38_initialize_session(session, session_media)) {
return -1;
+ }
+
+ if (session->t38state == T38_LOCAL_REINVITE) {
+ t38_interpret_sdp(state, session, session_media, stream);
+ t38_change_state(session, session_media, state, T38_ENABLED);
}
return 1;
More information about the asterisk-commits
mailing list