summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--Makefile2
-rw-r--r--addons/cdr_mysql.c8
-rw-r--r--addons/chan_ooh323.c19
-rw-r--r--addons/ooh323c/src/context.c1
-rw-r--r--addons/ooh323c/src/memheap.c11
-rw-r--r--addons/ooh323c/src/ooCalls.c3
-rw-r--r--addons/ooh323c/src/ooCapability.c8
-rw-r--r--addons/ooh323c/src/ooGkClient.c3
-rw-r--r--addons/ooh323c/src/ooh245.c2
-rw-r--r--addons/ooh323c/src/ooq931.c6
-rw-r--r--apps/app_confbridge.c7
-rw-r--r--apps/confbridge/conf_config_parser.c84
-rw-r--r--apps/confbridge/include/confbridge.h3
-rw-r--r--autoconf/ast_ext_tool_check.m42
-rw-r--r--autoconf/ast_pkgconfig.m42
-rw-r--r--bridges/bridge_softmix.c250
-rw-r--r--bridges/bridge_softmix/include/bridge_softmix_internal.h14
-rw-r--r--channels/chan_pjsip.c6
-rw-r--r--channels/chan_sip.c18
-rw-r--r--channels/chan_vpb.cc125
-rw-r--r--channels/pjsip/dialplan_functions.c8
-rw-r--r--configs/samples/confbridge.conf.sample4
-rwxr-xr-xconfigure28
-rwxr-xr-xcontrib/scripts/install_prereq27
-rwxr-xr-xcontrib/scripts/refcounter.py23
-rwxr-xr-xcontrib/scripts/spandspflow2pcap.py2
-rwxr-xr-xcontrib/scripts/voicemailpwcheck.py10
-rw-r--r--doc/.gitignore1
-rw-r--r--formats/format_pcm.c41
-rw-r--r--include/asterisk/bridge.h44
-rw-r--r--include/asterisk/res_pjsip.h133
-rw-r--r--include/asterisk/rtp_engine.h6
-rw-r--r--include/asterisk/sdp.h703
-rw-r--r--include/asterisk/sdp_options.h774
-rw-r--r--include/asterisk/sdp_state.h345
-rw-r--r--include/asterisk/sdp_translator.h103
-rw-r--r--include/asterisk/stasis_bridges.h4
-rw-r--r--include/asterisk/stream.h78
-rw-r--r--include/asterisk/utils.h13
-rw-r--r--main/Makefile3
-rw-r--r--main/bridge.c21
-rw-r--r--main/cli.c12
-rw-r--r--main/sdp.c951
-rw-r--r--main/sdp_options.c235
-rw-r--r--main/sdp_private.h78
-rw-r--r--main/sdp_state.c3411
-rw-r--r--main/sdp_translator.c104
-rw-r--r--main/stasis_bridges.c3
-rw-r--r--main/stream.c135
-rw-r--r--menuselect/Makefile8
-rw-r--r--menuselect/autoconfig.h.in4
-rwxr-xr-xmenuselect/configure37
-rw-r--r--menuselect/configure.ac40
-rw-r--r--res/Makefile3
-rw-r--r--res/res_musiconhold.c1
-rw-r--r--res/res_pjsip.c93
-rw-r--r--res/res_pjsip/config_system.c2
-rw-r--r--res/res_pjsip/config_transport.c2
-rw-r--r--res/res_pjsip/location.c5
-rw-r--r--res/res_pjsip/pjsip_configuration.c2
-rw-r--r--res/res_pjsip/pjsip_scheduler.c311
-rw-r--r--res/res_pjsip_header_funcs.c22
-rw-r--r--res/res_pjsip_history.c2
-rw-r--r--res/res_pjsip_notify.c230
-rw-r--r--res/res_pjsip_outbound_publish.c6
-rw-r--r--res/res_pjsip_outbound_registration.c7
-rw-r--r--res/res_pjsip_pubsub.c51
-rw-r--r--res/res_pjsip_refer.c18
-rw-r--r--res/res_pjsip_registrar.c34
-rw-r--r--res/res_pjsip_sdp_rtp.c3
-rw-r--r--res/res_pjsip_session.c2
-rw-r--r--res/res_pjsip_transport_websocket.c6
-rw-r--r--res/res_rtp_asterisk.c171
-rw-r--r--res/res_sdp_translator_pjmedia.c605
-rw-r--r--rest-api-templates/api.wiki.mustache2
-rw-r--r--rest-api-templates/ari_resource.h.mustache6
-rw-r--r--rest-api-templates/asterisk_processor.py8
-rwxr-xr-xrest-api-templates/make_ari_stubs.py5
-rw-r--r--rest-api-templates/res_ari_resource.c.mustache6
-rw-r--r--rest-api-templates/swagger_model.py19
-rw-r--r--rest-api-templates/transform.py9
-rw-r--r--tests/test_sdp.c2105
-rw-r--r--tests/test_stream.c120
-rw-r--r--utils/Makefile3
85 files changed, 1867 insertions, 9960 deletions
diff --git a/CHANGES b/CHANGES
index ac50a6dc9..3a81ca7ba 100644
--- a/CHANGES
+++ b/CHANGES
@@ -122,6 +122,11 @@ res_pjproject
MALLOC_DEBUG. The cache gets in the way of determining if the pool contents
are used after free and who freed it.
+res_pjsip_notify
+------------------
+ * Extend the PJSIPNotify AMI command to send an in-dialog notify on a
+ channel.
+
------------------------------------------------------------------------------
--- Functionality changes from Asterisk 15.2.0 to Asterisk 15.3.0 ------------
------------------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index 2c10dc497..1cd96650f 100644
--- a/Makefile
+++ b/Makefile
@@ -511,7 +511,7 @@ else
@echo "<!DOCTYPE docs SYSTEM \"appdocsxml.dtd\">" >> $@
@echo "<?xml-stylesheet type=\"text/xsl\" href=\"appdocsxml.xslt\"?>" >> $@
@echo "<docs xmlns:xi=\"http://www.w3.org/2001/XInclude\">" >> $@
- @for x in $(MOD_SUBDIRS); do \
+ @for x in $(filter-out third-party,$(MOD_SUBDIRS)); do \
printf "$$x " ; \
for i in `find $$x -name '*.c'`; do \
$(PYTHON) build_tools/get_documentation.py < $$i >> $@ ; \
diff --git a/addons/cdr_mysql.c b/addons/cdr_mysql.c
index 2fefe4ed1..97ebdf26f 100644
--- a/addons/cdr_mysql.c
+++ b/addons/cdr_mysql.c
@@ -58,6 +58,14 @@
#define DATE_FORMAT "%Y-%m-%d %T"
+#ifndef MYSQL_PORT
+# ifdef MARIADB_PORT
+# define MYSQL_PORT MARIADB_PORT
+# else
+# define MYSQL_PORT 3306
+# endif
+#endif
+
AST_THREADSTORAGE(sql1_buf);
AST_THREADSTORAGE(sql2_buf);
AST_THREADSTORAGE(escape_buf);
diff --git a/addons/chan_ooh323.c b/addons/chan_ooh323.c
index 06096507f..4ab90be3a 100644
--- a/addons/chan_ooh323.c
+++ b/addons/chan_ooh323.c
@@ -1282,7 +1282,7 @@ static int ooh323_indicate(struct ast_channel *ast, int condition, const void *d
struct ooh323_pvt *p = (struct ooh323_pvt *) ast_channel_tech_pvt(ast);
char *callToken = (char *)NULL;
- int res = -1;
+ int res = -1, rres;
if (!p) return -1;
@@ -1329,11 +1329,9 @@ static int ooh323_indicate(struct ast_channel *ast, int condition, const void *d
case AST_CONTROL_PROGRESS:
if (ast_channel_state(ast) != AST_STATE_UP) {
if (!p->progsent) {
+ rres = ooManualProgress(callToken);
if (gH323Debug) {
- ast_debug(1, "Sending manual progress for %s, res = %u\n", callToken,
- ooManualProgress(callToken));
- } else {
- ooManualProgress(callToken);
+ ast_debug(1, "Sending manual progress for %s, res = %u\n", callToken, rres);
}
p->progsent = 1;
}
@@ -1342,12 +1340,9 @@ static int ooh323_indicate(struct ast_channel *ast, int condition, const void *d
case AST_CONTROL_RINGING:
if (ast_channel_state(ast) == AST_STATE_RING || ast_channel_state(ast) == AST_STATE_RINGING) {
if (!p->alertsent) {
+ rres = ooManualRingback(callToken);
if (gH323Debug) {
- ast_debug(1, "Sending manual ringback for %s, res = %u\n",
- callToken,
- ooManualRingback(callToken));
- } else {
- ooManualRingback(callToken);
+ ast_debug(1, "Sending manual ringback for %s, res = %u\n", callToken, rres);
}
p->alertsent = 1;
}
@@ -5058,9 +5053,7 @@ struct ast_frame *ooh323_rtp_read(struct ast_channel *ast, struct ooh323_pvt *p)
ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", ast_channel_name(p->owner),target_context);
}
p->faxdetected = 1;
- if (dfr) {
- ast_frfree(dfr);
- }
+ ast_frfree(dfr);
return &ast_null_frame;
}
}
diff --git a/addons/ooh323c/src/context.c b/addons/ooh323c/src/context.c
index bc3db4387..c1e2003a2 100644
--- a/addons/ooh323c/src/context.c
+++ b/addons/ooh323c/src/context.c
@@ -164,6 +164,7 @@ OOCTXT* newContext ()
/* ASN1CRTFREE0 (pctxt); */
ast_free(pctxt);
pctxt = 0;
+ return (pctxt);
}
pctxt->flags |= ASN1DYNCTXT;
}
diff --git a/addons/ooh323c/src/memheap.c b/addons/ooh323c/src/memheap.c
index 4bcbd7a3d..4020261bb 100644
--- a/addons/ooh323c/src/memheap.c
+++ b/addons/ooh323c/src/memheap.c
@@ -623,7 +623,7 @@ void memHeapFreePtr (void** ppvMemHeap, void* mem_p)
}
}
}
- if (!ISLAST (pElem) && ISFREE (GETNEXT (pElem))) {
+ if (pElem && !ISLAST (pElem) && ISFREE (GETNEXT (pElem))) {
OSMemElemDescr* nextelem_p = GETNEXT (pElem);
/* +1 because the OSMemElemDescr has size ONE unit (8 bytes) */
@@ -638,7 +638,7 @@ void memHeapFreePtr (void** ppvMemHeap, void* mem_p)
}
/* correct the prevOff field of next element */
- if (!ISLAST (pElem)) {
+ if (pElem && !ISLAST (pElem)) {
OSMemElemDescr* nextelem_p = GETNEXT (pElem);
pElem_prevOff (nextelem_p) = QOFFSETOF (nextelem_p, pElem);
}
@@ -686,7 +686,7 @@ static void initNewFreeElement (OSMemBlk* pMemBlk,
}
pNextElem = GETNEXT (pNewElem);
- if (ISFREE (pNextElem)) {
+ if (pNextElem && ISFREE (pNextElem)) {
/* if the next elem is free, then unite them together */
@@ -820,7 +820,7 @@ void* memHeapRealloc (void** ppvMemHeap, void* mem_p, int nbytes_)
/* look for free element after pElem */
pNextElem = GETNEXT (pElem);
- if (ISFREE (pNextElem)) {
+ if (pNextElem && ISFREE (pNextElem)) {
/* +1 'cos sizeof (OSMemElemDescr) == 1 unit */
sumSize += pElem_nunits (pNextElem) + 1;
freeMem++;
@@ -1062,7 +1062,7 @@ void memHeapAddRef (void** ppvMemHeap)
void memHeapRelease (void** ppvMemHeap)
{
OSMemHeap** ppMemHeap = (OSMemHeap**)ppvMemHeap;
- OSMemHeap* pMemHeap = *ppMemHeap;
+ OSMemHeap* pMemHeap;
if (ppMemHeap != 0 && *ppMemHeap != 0 && --(*ppMemHeap)->refCnt == 0) {
OSMemLink* pMemLink, *pMemLink2;
@@ -1080,6 +1080,7 @@ void memHeapRelease (void** ppvMemHeap)
}
if ((*ppMemHeap)->flags & RT_MH_FREEHEAPDESC) {
+ pMemHeap = *ppMemHeap;
ast_mutex_destroy(&pMemHeap->pLock);
ast_free(*ppMemHeap);
}
diff --git a/addons/ooh323c/src/ooCalls.c b/addons/ooh323c/src/ooCalls.c
index 3097c6d28..15ab3258f 100644
--- a/addons/ooh323c/src/ooCalls.c
+++ b/addons/ooh323c/src/ooCalls.c
@@ -805,8 +805,7 @@ int ooAddMediaInfo(OOH323CallData *call, OOMediaInfo mediaInfo)
if(!call)
{
- OOTRACEERR3("Error:Invalid 'call' param for ooAddMediaInfo.(%s, %s)\n",
- call->callType, call->callToken);
+ OOTRACEERR1("Error:Invalid 'call' param for ooAddMediaInfo.\n");
return OO_FAILED;
}
newMediaInfo = (OOMediaInfo*) memAlloc(call->pctxt, sizeof(OOMediaInfo));
diff --git a/addons/ooh323c/src/ooCapability.c b/addons/ooh323c/src/ooCapability.c
index 731478346..0796c46bf 100644
--- a/addons/ooh323c/src/ooCapability.c
+++ b/addons/ooh323c/src/ooCapability.c
@@ -62,8 +62,6 @@ int ooCapabilityEnableDTMFCISCO
/*Dynamic RTP payload type range is from 96 - 127 */
if(dynamicRTPPayloadType >= 96 && dynamicRTPPayloadType <= 127)
gcDynamicRTPPayloadType = dynamicRTPPayloadType;
- else
- call->dtmfcodec = dynamicRTPPayloadType;
}
else{
call->dtmfmode |= OO_CAP_DTMF_CISCO;
@@ -623,8 +621,7 @@ int ooCapabilityAddT38Capability
else pctxt = call->pctxt;
epCap = (ooH323EpCapability*)memAllocZ(pctxt, sizeof(ooH323EpCapability));
- params = (OOCapParams*) memAlloc(pctxt, sizeof(OOCapParams));
- memset(params, 0 , sizeof(OOCapParams));
+ params = (OOCapParams*) memAllocZ(pctxt, sizeof(OOCapParams));
if(!epCap || !params)
{
OOTRACEERR1("ERROR: Memory - ooCapabilityAddT38Capability - "
@@ -808,8 +805,7 @@ void* ooCapabilityCreateDTMFCapability(int cap, int dtmfcodec, OOCTXT *pctxt)
}
memset(pATECap, 0, sizeof(H245AudioTelephonyEventCapability));
pATECap->dynamicRTPPayloadType = dtmfcodec;
- events = (char*)memAlloc(pctxt, strlen("0-16")+1);
- memset(events, 0, strlen("0-16")+1);
+ events = (char*)memAllocZ(pctxt, strlen("0-16")+1);
if(!events)
{
OOTRACEERR1("Error:Memory - ooCapabilityCreateDTMFCapability - events\n");
diff --git a/addons/ooh323c/src/ooGkClient.c b/addons/ooh323c/src/ooGkClient.c
index 4f7883833..5ec33eef9 100644
--- a/addons/ooh323c/src/ooGkClient.c
+++ b/addons/ooh323c/src/ooGkClient.c
@@ -2336,9 +2336,8 @@ int ooGkClientSendIRR
pIRR->m.perCallInfoPresent = TRUE;
perCallInfo =
- (H225InfoRequestResponse_perCallInfo_element *)memAlloc(pctxt,
+ (H225InfoRequestResponse_perCallInfo_element *)memAllocZ(pctxt,
sizeof(H225InfoRequestResponse_perCallInfo_element));
- memset(perCallInfo, 0, sizeof(H225InfoRequestResponse_perCallInfo_element));
if(!perCallInfo)
{
diff --git a/addons/ooh323c/src/ooh245.c b/addons/ooh323c/src/ooh245.c
index adff91790..fe8ff28e0 100644
--- a/addons/ooh323c/src/ooh245.c
+++ b/addons/ooh323c/src/ooh245.c
@@ -356,7 +356,6 @@ int ooSendTermCapMsg(OOH323CallData *call)
/* pctxt = &gH323ep.msgctxt; */
pctxt = call->msgctxt;
ph245msg->msgType = OOTerminalCapabilitySet;
- memset(request, 0, sizeof(H245RequestMessage));
if(request == NULL)
{
OOTRACEERR3("ERROR: No memory allocated for request message (%s, %s)\n",
@@ -364,6 +363,7 @@ int ooSendTermCapMsg(OOH323CallData *call)
return OO_FAILED;
}
+ memset(request, 0, sizeof(H245RequestMessage));
request->t = T_H245RequestMessage_terminalCapabilitySet;
request->u.terminalCapabilitySet = (H245TerminalCapabilitySet*)
memAlloc(pctxt, sizeof(H245TerminalCapabilitySet));
diff --git a/addons/ooh323c/src/ooq931.c b/addons/ooh323c/src/ooq931.c
index 1ca361c2c..01a8e4aaf 100644
--- a/addons/ooh323c/src/ooq931.c
+++ b/addons/ooh323c/src/ooq931.c
@@ -2439,8 +2439,10 @@ int ooH323HandleCallFwdRequest(OOH323CallData *call)
alias = call->pCallFwdData->aliases;
while(alias)
{
- pNewAlias = (ooAliases*) memAlloc(pctxt, sizeof(ooAliases));
- pNewAlias->value = (char*) memAlloc(pctxt, strlen(alias->value)+1);
+ pNewAlias = (ooAliases*) memAllocZ(pctxt, sizeof(ooAliases));
+ if (pNewAlias) {
+ pNewAlias->value = (char*) memAllocZ(pctxt, strlen(alias->value)+1);
+ }
if(!pNewAlias || !pNewAlias->value)
{
OOTRACEERR3("Error:Memory - ooH323HandleCallFwdRequest - "
diff --git a/apps/app_confbridge.c b/apps/app_confbridge.c
index d8407d857..25cf2758f 100644
--- a/apps/app_confbridge.c
+++ b/apps/app_confbridge.c
@@ -1544,6 +1544,13 @@ static struct confbridge_conference *join_conference_bridge(const char *conferen
ast_bridge_set_sfu_video_mode(conference->bridge);
ast_bridge_set_video_update_discard(conference->bridge, conference->b_profile.video_update_discard);
ast_bridge_set_remb_send_interval(conference->bridge, conference->b_profile.remb_send_interval);
+ if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_AVERAGE)) {
+ ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_AVERAGE);
+ } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_LOWEST)) {
+ ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_LOWEST);
+ } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_REMB_BEHAVIOR_HIGHEST)) {
+ ast_brige_set_remb_behavior(conference->bridge, AST_BRIDGE_VIDEO_SFU_REMB_HIGHEST);
+ }
}
/* Link it into the conference bridges container */
diff --git a/apps/confbridge/conf_config_parser.c b/apps/confbridge/conf_config_parser.c
index f9d74831c..873831911 100644
--- a/apps/confbridge/conf_config_parser.c
+++ b/apps/confbridge/conf_config_parser.c
@@ -470,6 +470,27 @@
better quality for all receivers.
</para></description>
</configOption>
+ <configOption name="remb_behavior" default="average">
+ <synopsis>Sets how REMB reports are generated from multiple sources</synopsis>
+ <description><para>
+ Sets how REMB reports are combined from multiple sources to form one. A REMB report
+ consists of information about the receiver estimated maximum bitrate. As a source
+ stream may be forwarded to multiple receivers the reports must be combined into
+ a single one which is sent to the sender.</para>
+ <enumlist>
+ <enum name="average">
+ <para>The average of all estimated maximum bitrates is taken and sent
+ to the sender.</para>
+ </enum>
+ <enum name="lowest">
+ <para>The lowest estimated maximum bitrate is forwarded to the sender.</para>
+ </enum>
+ <enum name="highest">
+ <para>The highest estimated maximum bitrate is forwarded to the sender.</para>
+ </enum>
+ </enumlist>
+ </description>
+ </configOption>
<configOption name="template">
<synopsis>When using the CONFBRIDGE dialplan function, use a bridge profile as a template for creating a new temporary profile</synopsis>
</configOption>
@@ -1652,8 +1673,10 @@ static char *handle_cli_confbridge_show_bridge_profile(struct ast_cli_entry *e,
ast_cli(a->fd,"Registration context: %s\n", b_profile.regcontext);
switch (b_profile.flags
- & (BRIDGE_OPT_VIDEO_SRC_LAST_MARKED | BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
- | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER)) {
+ & (BRIDGE_OPT_VIDEO_SRC_LAST_MARKED |
+ BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED |
+ BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER |
+ BRIDGE_OPT_VIDEO_SRC_SFU)) {
case BRIDGE_OPT_VIDEO_SRC_LAST_MARKED:
ast_cli(a->fd, "Video Mode: last_marked\n");
break;
@@ -1663,6 +1686,9 @@ static char *handle_cli_confbridge_show_bridge_profile(struct ast_cli_entry *e,
case BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER:
ast_cli(a->fd, "Video Mode: follow_talker\n");
break;
+ case BRIDGE_OPT_VIDEO_SRC_SFU:
+ ast_cli(a->fd, "Video Mode: sfu\n");
+ break;
case 0:
ast_cli(a->fd, "Video Mode: no video\n");
break;
@@ -1675,6 +1701,23 @@ static char *handle_cli_confbridge_show_bridge_profile(struct ast_cli_entry *e,
ast_cli(a->fd,"Video Update Discard: %u\n", b_profile.video_update_discard);
ast_cli(a->fd,"REMB Send Interval: %u\n", b_profile.remb_send_interval);
+ switch (b_profile.flags
+ & (BRIDGE_OPT_REMB_BEHAVIOR_AVERAGE | BRIDGE_OPT_REMB_BEHAVIOR_LOWEST
+ | BRIDGE_OPT_REMB_BEHAVIOR_HIGHEST)) {
+ case BRIDGE_OPT_REMB_BEHAVIOR_AVERAGE:
+ ast_cli(a->fd, "REMB Behavior: average\n");
+ break;
+ case BRIDGE_OPT_REMB_BEHAVIOR_LOWEST:
+ ast_cli(a->fd, "REMB Behavior: lowest\n");
+ break;
+ case BRIDGE_OPT_REMB_BEHAVIOR_HIGHEST:
+ ast_cli(a->fd, "REMB Behavior: highest\n");
+ break;
+ default:
+ ast_assert(0);
+ break;
+ }
+
ast_cli(a->fd,"sound_only_person: %s\n", conf_get_sound(CONF_SOUND_ONLY_PERSON, b_profile.sounds));
ast_cli(a->fd,"sound_only_one: %s\n", conf_get_sound(CONF_SOUND_ONLY_ONE, b_profile.sounds));
ast_cli(a->fd,"sound_has_joined: %s\n", conf_get_sound(CONF_SOUND_HAS_JOINED, b_profile.sounds));
@@ -1992,12 +2035,6 @@ static int video_mode_handler(const struct aco_option *opt, struct ast_variable
| BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER
| BRIDGE_OPT_VIDEO_SRC_SFU,
BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER);
- } else if (!strcasecmp(var->value, "none")) {
- ast_clear_flag(b_profile,
- BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
- | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
- | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER
- | BRIDGE_OPT_VIDEO_SRC_SFU);
} else if (!strcasecmp(var->value, "sfu")) {
ast_set_flags_to(b_profile,
BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
@@ -2005,6 +2042,36 @@ static int video_mode_handler(const struct aco_option *opt, struct ast_variable
| BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER
| BRIDGE_OPT_VIDEO_SRC_SFU,
BRIDGE_OPT_VIDEO_SRC_SFU);
+ } else if (!strcasecmp(var->value, "none")) {
+ ast_clear_flag(b_profile,
+ BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
+ | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
+ | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER
+ | BRIDGE_OPT_VIDEO_SRC_SFU);
+ } else {
+ return -1;
+ }
+ return 0;
+}
+
+static int remb_behavior_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+ struct bridge_profile *b_profile = obj;
+
+ if (strcasecmp(var->name, "remb_behavior")) {
+ return -1;
+ }
+
+ ast_clear_flag(b_profile, BRIDGE_OPT_REMB_BEHAVIOR_AVERAGE |
+ BRIDGE_OPT_REMB_BEHAVIOR_LOWEST |
+ BRIDGE_OPT_REMB_BEHAVIOR_HIGHEST);
+
+ if (!strcasecmp(var->value, "average")) {
+ ast_set_flag(b_profile, BRIDGE_OPT_REMB_BEHAVIOR_AVERAGE);
+ } else if (!strcasecmp(var->value, "lowest")) {
+ ast_set_flag(b_profile, BRIDGE_OPT_REMB_BEHAVIOR_LOWEST);
+ } else if (!strcasecmp(var->value, "highest")) {
+ ast_set_flag(b_profile, BRIDGE_OPT_REMB_BEHAVIOR_HIGHEST);
} else {
return -1;
}
@@ -2245,6 +2312,7 @@ int conf_load_config(void)
aco_option_register_custom(&cfg_info, "sound_", ACO_PREFIX, bridge_types, NULL, sound_option_handler, 0);
aco_option_register(&cfg_info, "video_update_discard", ACO_EXACT, bridge_types, "2000", OPT_UINT_T, 0, FLDSET(struct bridge_profile, video_update_discard));
aco_option_register(&cfg_info, "remb_send_interval", ACO_EXACT, bridge_types, "0", OPT_UINT_T, 0, FLDSET(struct bridge_profile, remb_send_interval));
+ aco_option_register_custom(&cfg_info, "remb_behavior", ACO_EXACT, bridge_types, "average", remb_behavior_handler, 0);
/* This option should only be used with the CONFBRIDGE dialplan function */
aco_option_register_custom(&cfg_info, "template", ACO_EXACT, bridge_types, NULL, bridge_template_handler, 0);
diff --git a/apps/confbridge/include/confbridge.h b/apps/confbridge/include/confbridge.h
index c2f8f9a58..0a0a5713f 100644
--- a/apps/confbridge/include/confbridge.h
+++ b/apps/confbridge/include/confbridge.h
@@ -76,6 +76,9 @@ enum bridge_profile_flags {
BRIDGE_OPT_RECORD_FILE_TIMESTAMP = (1 << 5), /*!< Set if the record file should have a timestamp appended */
BRIDGE_OPT_BINAURAL_ACTIVE = (1 << 6), /*!< Set if binaural convolution is activated */
BRIDGE_OPT_VIDEO_SRC_SFU = (1 << 7), /*!< Selective forwarding unit */
+ BRIDGE_OPT_REMB_BEHAVIOR_AVERAGE = (1 << 8), /*!< The average of all REMB reports is sent to the sender */
+ BRIDGE_OPT_REMB_BEHAVIOR_LOWEST = (1 << 9), /*!< The lowest estimated maximum bitrate is sent to the sender */
+ BRIDGE_OPT_REMB_BEHAVIOR_HIGHEST = (1 << 10), /*!< The highest estimated maximum bitrate is sent to the sender */
};
enum conf_menu_action_id {
diff --git a/autoconf/ast_ext_tool_check.m4 b/autoconf/ast_ext_tool_check.m4
index ef762eb87..cbe109e4a 100644
--- a/autoconf/ast_ext_tool_check.m4
+++ b/autoconf/ast_ext_tool_check.m4
@@ -11,7 +11,7 @@ AC_DEFUN([AST_EXT_TOOL_CHECK],
AC_PATH_TOOL(CONFIG_$1, $2, No, [${$1_DIR}/bin:$PATH])
if test ! "x${CONFIG_$1}" = xNo; then
$1_INCLUDE=$(${CONFIG_$1} m4_default([$3],[--cflags]))
- $1_INCLUDE=$(echo ${$1_INCLUDE} | $SED -e "s|-I|-I${$1_DIR}|g")
+ $1_INCLUDE=$(echo ${$1_INCLUDE} | $SED -e "s|-I|-I${$1_DIR}|g" -e "s|-std=c99||g")
$1_LIB=$(${CONFIG_$1} m4_default([$4],[--libs]))
$1_LIB=$(echo ${$1_LIB} | $SED -e "s|-L|-L${$1_DIR}|g")
diff --git a/autoconf/ast_pkgconfig.m4 b/autoconf/ast_pkgconfig.m4
index ae7bbc086..3415ed547 100644
--- a/autoconf/ast_pkgconfig.m4
+++ b/autoconf/ast_pkgconfig.m4
@@ -5,7 +5,7 @@ AC_DEFUN([AST_PKG_CONFIG_CHECK],
if test "x${PBX_$1}" != "x1" -a "${USE_$1}" != "no"; then
PKG_CHECK_MODULES($1, $2, [
PBX_$1=1
- $1_INCLUDE="$$1_CFLAGS"
+ $1_INCLUDE=$(echo ${$1_CFLAGS} | $SED -e "s|-std=c99||g")
$1_LIB="$$1_LIBS"
AC_DEFINE([HAVE_$1], 1, [Define if your system has the $1 libraries.])
], [
diff --git a/bridges/bridge_softmix.c b/bridges/bridge_softmix.c
index 16e1fb897..ed88b7cd5 100644
--- a/bridges/bridge_softmix.c
+++ b/bridges/bridge_softmix.c
@@ -69,6 +69,15 @@
#define SOFTBRIDGE_VIDEO_DEST_LEN strlen(SOFTBRIDGE_VIDEO_DEST_PREFIX)
#define SOFTBRIDGE_VIDEO_DEST_SEPARATOR '_'
+struct softmix_remb_collector {
+ /*! The frame which will be given to each source stream */
+ struct ast_frame frame;
+ /*! The REMB to send to the source which is collecting REMB reports */
+ struct ast_rtp_rtcp_feedback feedback;
+ /*! The maximum bitrate */
+ unsigned int bitrate;
+};
+
struct softmix_stats {
/*! Each index represents a sample rate used above the internal rate. */
unsigned int sample_rates[16];
@@ -768,6 +777,10 @@ static void softmix_bridge_leave(struct ast_bridge *bridge, struct ast_bridge_ch
ast_stream_topology_free(sc->topology);
+ ao2_cleanup(sc->remb_collector);
+
+ AST_VECTOR_FREE(&sc->video_sources);
+
/* Drop mutex lock */
ast_mutex_destroy(&sc->lock);
@@ -1160,6 +1173,39 @@ static int softmix_bridge_write_control(struct ast_bridge *bridge, struct ast_br
/*!
* \internal
+ * \brief Determine what to do with an RTCP frame.
+ * \since 15.4.0
+ *
+ * \param bridge Which bridge is getting the frame
+ * \param bridge_channel Which channel is writing the frame.
+ * \param frame What is being written.
+ */
+static void softmix_bridge_write_rtcp(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
+{
+ struct ast_rtp_rtcp_feedback *feedback = frame->data.ptr;
+ struct softmix_channel *sc = bridge_channel->tech_pvt;
+
+ /* We only care about REMB reports right now. In the future we may be able to use sender or
+ * receiver reports to further tweak things, but not yet.
+ */
+ if (frame->subclass.integer != AST_RTP_RTCP_PSFB || feedback->fmt != AST_RTP_RTCP_FMT_REMB ||
+ bridge->softmix.video_mode.mode != AST_BRIDGE_VIDEO_MODE_SFU ||
+ !bridge->softmix.video_mode.mode_data.sfu_data.remb_send_interval) {
+ return;
+ }
+
+ /* REMB is the total estimated maximum bitrate across all streams within the session, so we store
+ * only the latest report and use it everywhere.
+ */
+ ast_mutex_lock(&sc->lock);
+ sc->remb = feedback->remb;
+ ast_mutex_unlock(&sc->lock);
+
+ return;
+}
+
+/*!
+ * \internal
* \brief Determine what to do with a frame written into the bridge.
* \since 12.0.0
*
@@ -1204,6 +1250,9 @@ static int softmix_bridge_write(struct ast_bridge *bridge, struct ast_bridge_cha
case AST_FRAME_CONTROL:
res = softmix_bridge_write_control(bridge, bridge_channel, frame);
break;
+ case AST_FRAME_RTCP:
+ softmix_bridge_write_rtcp(bridge, bridge_channel, frame);
+ break;
case AST_FRAME_BRIDGE_ACTION:
res = ast_bridge_queue_everyone_else(bridge, bridge_channel, frame);
break;
@@ -1219,6 +1268,108 @@ static int softmix_bridge_write(struct ast_bridge *bridge, struct ast_bridge_cha
return res;
}
+static void remb_collect_report(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel,
+ struct softmix_bridge_data *softmix_data, struct softmix_channel *sc)
+{
+ int i;
+ unsigned int bitrate;
+
+ /* If there are no video sources that we are a receiver of then we have noone to
+ * report REMB to.
+ */
+ if (!AST_VECTOR_SIZE(&sc->video_sources)) {
+ return;
+ }
+
+ /* We evenly divide the available maximum bitrate across the video sources
+ * to this receiver so each source gets an equal slice.
+ */
+ bitrate = (sc->remb.br_mantissa << sc->remb.br_exp) / AST_VECTOR_SIZE(&sc->video_sources);
+
+ /* If this receiver has no bitrate yet ignore it */
+ if (!bitrate) {
+ return;
+ }
+
+ for (i = 0; i < AST_VECTOR_SIZE(&sc->video_sources); ++i) {
+ struct softmix_remb_collector *collector;
+
+ /* The collector will always exist if a video source is in our list */
+ collector = AST_VECTOR_GET(&softmix_data->remb_collectors, AST_VECTOR_GET(&sc->video_sources, i));
+
+ if (!collector->bitrate) {
+ collector->bitrate = bitrate;
+ continue;
+ }
+
+ switch (bridge->softmix.video_mode.mode_data.sfu_data.remb_behavior) {
+ case AST_BRIDGE_VIDEO_SFU_REMB_AVERAGE:
+ collector->bitrate = (collector->bitrate + bitrate) / 2;
+ break;
+ case AST_BRIDGE_VIDEO_SFU_REMB_LOWEST:
+ if (bitrate < collector->bitrate) {
+ collector->bitrate = bitrate;
+ }
+ break;
+ case AST_BRIDGE_VIDEO_SFU_REMB_HIGHEST:
+ if (bitrate > collector->bitrate) {
+ collector->bitrate = bitrate;
+ }
+ break;
+ }
+ }
+
+ /* After the report is integrated we reset this to 0 in case they stop producing
+ * REMB reports.
+ */
+ sc->remb.br_mantissa = 0;
+ sc->remb.br_exp = 0;
+}
+
+static void remb_send_report(struct ast_bridge_channel *bridge_channel, struct softmix_channel *sc)
+{
+ int i;
+
+ if (!sc->remb_collector) {
+ return;
+ }
+
+ /* We always do this calculation as even when the bitrate is zero the browser
+ * still prefers it to be accurate instead of lying.
+ */
+ sc->remb_collector->feedback.remb.br_mantissa = sc->remb_collector->bitrate;
+ sc->remb_collector->feedback.remb.br_exp = 0;
+
+ /* The mantissa only has 18 bits available, so while it exceeds them we bump
+ * up the exp.
+ */
+ while (sc->remb_collector->feedback.remb.br_mantissa > 0x3ffff) {
+ sc->remb_collector->feedback.remb.br_mantissa = sc->remb_collector->feedback.remb.br_mantissa >> 1;
+ sc->remb_collector->feedback.remb.br_exp++;
+ }
+
+ for (i = 0; i < AST_VECTOR_SIZE(&bridge_channel->stream_map.to_bridge); ++i) {
+ int bridge_num = AST_VECTOR_GET(&bridge_channel->stream_map.to_bridge, i);
+
+ /* If this stream is not being provided to the bridge there can be no receivers of it
+ * so therefore no REMB reports.
+ */
+ if (bridge_num == -1) {
+ continue;
+ }
+
+ /* We need to update the frame with this stream, or else it won't be
+ * properly routed. We don't use the actual channel stream identifier as
+ * the bridging core will do the translation from bridge stream identifier to
+ * channel stream identifier.
+ */
+ sc->remb_collector->frame.stream_num = bridge_num;
+ ast_bridge_channel_queue_frame(bridge_channel, &sc->remb_collector->frame);
+ }
+
+ sc->remb_collector->bitrate = 0;
+}
+
static void gather_softmix_stats(struct softmix_stats *stats,
const struct softmix_bridge_data *softmix_data,
struct ast_bridge_channel *bridge_channel)
@@ -1440,6 +1591,7 @@ static int softmix_mixing_loop(struct ast_bridge *bridge)
struct ast_format *cur_slin = ast_format_cache_get_slin_by_rate(softmix_data->internal_rate);
unsigned int softmix_samples = SOFTMIX_SAMPLES(softmix_data->internal_rate, softmix_data->internal_mixing_interval);
unsigned int softmix_datalen = SOFTMIX_DATALEN(softmix_data->internal_rate, softmix_data->internal_mixing_interval);
+ int remb_update = 0;
if (softmix_datalen > MAX_DATALEN) {
/* This should NEVER happen, but if it does we need to know about it. Almost
@@ -1478,6 +1630,14 @@ static int softmix_mixing_loop(struct ast_bridge *bridge)
check_binaural_position_change(bridge, softmix_data);
#endif
+ /* If we need to do a REMB update to all video sources then do so */
+ if (bridge->softmix.video_mode.mode == AST_BRIDGE_VIDEO_MODE_SFU &&
+ bridge->softmix.video_mode.mode_data.sfu_data.remb_send_interval &&
+ ast_tvdiff_ms(ast_tvnow(), softmix_data->last_remb_update) > bridge->softmix.video_mode.mode_data.sfu_data.remb_send_interval) {
+ remb_update = 1;
+ softmix_data->last_remb_update = ast_tvnow();
+ }
+
/* Go through pulling audio from each factory that has it available */
AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
struct softmix_channel *sc = bridge_channel->tech_pvt;
@@ -1512,6 +1672,9 @@ static int softmix_mixing_loop(struct ast_bridge *bridge)
#endif
mixing_array.used_entries++;
}
+ if (remb_update) {
+ remb_collect_report(bridge, bridge_channel, softmix_data, sc);
+ }
ast_mutex_unlock(&sc->lock);
}
@@ -1562,6 +1725,10 @@ static int softmix_mixing_loop(struct ast_bridge *bridge)
/* A frame is now ready for the channel. */
ast_bridge_channel_queue_frame(bridge_channel, &sc->write_frame);
+
+ if (remb_update) {
+ remb_send_report(bridge_channel, sc);
+ }
}
update_all_rates = 0;
@@ -1688,6 +1855,8 @@ static void softmix_bridge_data_destroy(struct softmix_bridge_data *softmix_data
}
ast_mutex_destroy(&softmix_data->lock);
ast_cond_destroy(&softmix_data->cond);
+ AST_VECTOR_RESET(&softmix_data->remb_collectors, ao2_cleanup);
+ AST_VECTOR_FREE(&softmix_data->remb_collectors);
ast_free(softmix_data);
}
@@ -1718,6 +1887,8 @@ static int softmix_bridge_create(struct ast_bridge *bridge)
softmix_data->internal_mixing_interval);
#endif
+ AST_VECTOR_INIT(&softmix_data->remb_collectors, 0);
+
bridge->tech_pvt = softmix_data;
/* Start the mixing thread. */
@@ -1814,7 +1985,10 @@ static void map_source_to_destinations(const char *source_stream_name, const cha
stream = ast_stream_topology_get_stream(topology, i);
if (is_video_dest(stream, source_channel_name, source_stream_name)) {
+ struct softmix_channel *sc = participant->tech_pvt;
+
AST_VECTOR_REPLACE(&participant->stream_map.to_channel, bridge_stream_position, i);
+ AST_VECTOR_APPEND(&sc->video_sources, bridge_stream_position);
break;
}
}
@@ -1824,6 +1998,58 @@ static void map_source_to_destinations(const char *source_stream_name, const cha
}
/*!
+ * \brief Allocate a REMB collector
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ */
+static struct softmix_remb_collector *remb_collector_alloc(void)
+{
+ struct softmix_remb_collector *collector;
+
+ collector = ao2_alloc_options(sizeof(*collector), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
+ if (!collector) {
+ return NULL;
+ }
+
+ collector->frame.frametype = AST_FRAME_RTCP;
+ collector->frame.subclass.integer = AST_RTP_RTCP_PSFB;
+ collector->feedback.fmt = AST_RTP_RTCP_FMT_REMB;
+ collector->frame.data.ptr = &collector->feedback;
+ collector->frame.datalen = sizeof(collector->feedback);
+
+ return collector;
+}
+
+/*!
+ * \brief Setup REMB collection for a particular bridge stream and channel.
+ *
+ * \param bridge The bridge
+ * \param bridge_channel Channel that is collecting REMB information
+ * \param bridge_stream_position The slot in the bridge where source video comes from
+ */
+static void remb_enable_collection(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel,
+ size_t bridge_stream_position)
+{
+ struct softmix_channel *sc = bridge_channel->tech_pvt;
+ struct softmix_bridge_data *softmix_data = bridge->tech_pvt;
+
+ if (!sc->remb_collector) {
+ sc->remb_collector = remb_collector_alloc();
+ if (!sc->remb_collector) {
+ /* This is not fatal. Things will still continue to work but we won't
+ * produce a REMB report to the sender.
+ */
+ return;
+ }
+ }
+
+ if (AST_VECTOR_REPLACE(&softmix_data->remb_collectors, bridge_stream_position, ao2_bump(sc->remb_collector))) {
+ ao2_ref(sc->remb_collector, -1);
+ }
+}
+
+/*!
* \brief stream_topology_changed callback
*
* For most video modes, nothing beyond the ordinary is required.
@@ -1835,9 +2061,12 @@ static void map_source_to_destinations(const char *source_stream_name, const cha
*/
static void softmix_bridge_stream_topology_changed(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
{
+ struct softmix_bridge_data *softmix_data = bridge->tech_pvt;
+ struct softmix_channel *sc;
struct ast_bridge_channel *participant;
struct ast_vector_int media_types;
int nths[AST_MEDIA_TYPE_END] = {0};
+ int idx;
switch (bridge->softmix.video_mode.mode) {
case AST_BRIDGE_VIDEO_MODE_NONE:
@@ -1852,11 +2081,25 @@ static void softmix_bridge_stream_topology_changed(struct ast_bridge *bridge, st
AST_VECTOR_INIT(&media_types, AST_MEDIA_TYPE_END);
+ /* The bridge stream identifiers may change, so reset the mapping for them.
+ * When channels end up getting added back in they'll reuse their existing
+ * collector and won't need to allocate a new one (unless they were just added).
+ */
+ for (idx = 0; idx < AST_VECTOR_SIZE(&softmix_data->remb_collectors); ++idx) {
+ ao2_cleanup(AST_VECTOR_GET(&softmix_data->remb_collectors, idx));
+ AST_VECTOR_REPLACE(&softmix_data->remb_collectors, idx, NULL);
+ }
+
/* First traversal: re-initialize all of the participants' stream maps */
AST_LIST_TRAVERSE(&bridge->channels, participant, entry) {
ast_bridge_channel_lock(participant);
+
AST_VECTOR_RESET(&participant->stream_map.to_channel, AST_VECTOR_ELEM_CLEANUP_NOOP);
AST_VECTOR_RESET(&participant->stream_map.to_bridge, AST_VECTOR_ELEM_CLEANUP_NOOP);
+
+ sc = participant->tech_pvt;
+ AST_VECTOR_RESET(&sc->video_sources, AST_VECTOR_ELEM_CLEANUP_NOOP);
+
ast_bridge_channel_unlock(participant);
}
@@ -1897,7 +2140,12 @@ static void softmix_bridge_stream_topology_changed(struct ast_bridge *bridge, st
if (is_video_source(stream)) {
AST_VECTOR_APPEND(&media_types, AST_MEDIA_TYPE_VIDEO);
AST_VECTOR_REPLACE(&participant->stream_map.to_bridge, i, AST_VECTOR_SIZE(&media_types) - 1);
- AST_VECTOR_REPLACE(&participant->stream_map.to_channel, AST_VECTOR_SIZE(&media_types) - 1, -1);
+ /*
+ * There are cases where we need to bidirectionally send frames, such as for REMB reports
+ * so we also map back to the channel.
+ */
+ AST_VECTOR_REPLACE(&participant->stream_map.to_channel, AST_VECTOR_SIZE(&media_types) - 1, i);
+ remb_enable_collection(bridge, participant, AST_VECTOR_SIZE(&media_types) - 1);
/*
* Unlock the channel and participant to prevent
* potential deadlock in map_source_to_destinations().
diff --git a/bridges/bridge_softmix/include/bridge_softmix_internal.h b/bridges/bridge_softmix/include/bridge_softmix_internal.h
index f842acb5e..3aa90915d 100644
--- a/bridges/bridge_softmix/include/bridge_softmix_internal.h
+++ b/bridges/bridge_softmix/include/bridge_softmix_internal.h
@@ -50,6 +50,8 @@
#include "asterisk/astobj2.h"
#include "asterisk/timing.h"
#include "asterisk/translate.h"
+#include "asterisk/rtp_engine.h"
+#include "asterisk/vector.h"
#ifdef BINAURAL_RENDERING
#include <fftw3.h>
@@ -124,6 +126,8 @@ struct video_follow_talker_data {
int energy_average;
};
+struct softmix_remb_collector;
+
/*! \brief Structure which contains per-channel mixing information */
struct softmix_channel {
/*! Lock to protect this structure */
@@ -169,6 +173,12 @@ struct softmix_channel {
struct video_follow_talker_data video_talker;
/*! The ideal stream topology for the channel */
struct ast_stream_topology *topology;
+ /*! The latest REMB report from this participant */
+ struct ast_rtp_rtcp_feedback_remb remb;
+ /*! The REMB collector for this channel, collects REMB from all video receivers */
+ struct softmix_remb_collector *remb_collector;
+ /*! The bridge streams which are feeding us video sources */
+ AST_VECTOR(, int) video_sources;
};
struct softmix_bridge_data {
@@ -202,6 +212,10 @@ struct softmix_bridge_data {
unsigned int binaural_init;
/*! The last time a video update was sent into the bridge */
struct timeval last_video_update;
+ /*! The last time a REMB frame was sent to each source of video */
+ struct timeval last_remb_update;
+ /*! Per-bridge stream REMB collectors, which flow back to video source */
+ AST_VECTOR(, struct softmix_remb_collector *) remb_collectors;
};
struct softmix_mixing_array {
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 6b2664819..dde7416c3 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -718,7 +718,7 @@ static int chan_pjsip_answer(struct ast_channel *ast)
can occur between this thread and bridging (specifically when native bridging
attempts to do direct media) */
ast_channel_unlock(ast);
- res = ast_sip_push_task_synchronous(session->serializer, answer, session);
+ res = ast_sip_push_task_wait_serializer(session->serializer, answer, session);
if (res) {
if (res == -1) {
ast_log(LOG_ERROR,"Cannot answer '%s': Unable to push answer task to the threadpool.\n",
@@ -2502,10 +2502,10 @@ static struct ast_channel *chan_pjsip_request_with_stream_topology(const char *t
req_data.topology = topology;
req_data.dest = data;
- /* Default failure value in case ast_sip_push_task_synchronous() itself fails. */
+ /* Default failure value in case ast_sip_push_task_wait_servant() itself fails. */
req_data.cause = AST_CAUSE_FAILURE;
- if (ast_sip_push_task_synchronous(NULL, request, &req_data)) {
+ if (ast_sip_push_task_wait_servant(NULL, request, &req_data)) {
*cause = req_data.cause;
return NULL;
}
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 138021e82..46f9ad699 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -25856,7 +25856,7 @@ static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req,
int *nounlock, struct sip_pvt *replaces_pvt, struct ast_channel *replaces_chan)
{
struct ast_channel *c;
- RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+ struct ast_bridge *bridge;
if (req->ignore) {
return 0;
@@ -25872,6 +25872,7 @@ static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req,
}
append_history(p, "Xfer", "INVITE/Replace received");
+ /* Get a ref to ensure the channel cannot go away on us. */
c = ast_channel_ref(p->owner);
/* Fake call progress */
@@ -25886,21 +25887,24 @@ static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req,
ast_raw_answer(c);
- ast_channel_lock(replaces_chan);
- bridge = ast_channel_get_bridge(replaces_chan);
- ast_channel_unlock(replaces_chan);
-
+ bridge = ast_bridge_transfer_acquire_bridge(replaces_chan);
if (bridge) {
+ /*
+ * We have two refs of the channel. One is held in c and the other
+ * is notionally represented by p->owner. The impart is "stealing"
+ * the p->owner ref on success so the bridging system can have
+ * control of when the channel is hung up.
+ */
if (ast_bridge_impart(bridge, c, replaces_chan, NULL,
AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
ast_hangup(c);
- ast_channel_unref(c);
}
+ ao2_ref(bridge, -1);
} else {
ast_channel_move(replaces_chan, c);
ast_hangup(c);
- ast_channel_unref(c);
}
+ ast_channel_unref(c);
sip_pvt_lock(p);
return 0;
}
diff --git a/channels/chan_vpb.cc b/channels/chan_vpb.cc
index 1736cc6b2..7fdb9edb7 100644
--- a/channels/chan_vpb.cc
+++ b/channels/chan_vpb.cc
@@ -108,7 +108,6 @@ extern "C" {
#endif
/**/
-static const char desc[] = "VoiceTronix V6PCI/V12PCI/V4PCI API Support";
static const char tdesc[] = "Standard VoiceTronix API Driver";
static const char config[] = "vpb.conf";
@@ -360,71 +359,71 @@ static int vpb_indicate(struct ast_channel *ast, int condition, const void *data
static int vpb_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
static struct ast_channel_tech vpb_tech = {
- type: "vpb",
- description: tdesc,
- capabilities: NULL,
- properties: 0,
- requester: vpb_request,
- requester_with_stream_topology: NULL,
- devicestate: NULL,
- presencestate: NULL,
- send_digit_begin: vpb_digit_begin,
- send_digit_end: vpb_digit_end,
- call: vpb_call,
- hangup: vpb_hangup,
- answer: vpb_answer,
- read: vpb_read,
- read_stream: NULL,
- write: vpb_write,
- write_stream: NULL,
- send_text: NULL,
- send_image: NULL,
- send_html: NULL,
- exception: NULL,
- early_bridge: NULL,
- indicate: vpb_indicate,
- fixup: vpb_fixup,
- setoption: NULL,
- queryoption: NULL,
- transfer: NULL,
- write_video: NULL,
- write_text: NULL,
- func_channel_read: NULL,
- func_channel_write: NULL,
+ .type = "vpb",
+ .description = tdesc,
+ .capabilities = NULL,
+ .properties = 0,
+ .requester = vpb_request,
+ .requester_with_stream_topology = NULL,
+ .devicestate = NULL,
+ .presencestate = NULL,
+ .send_digit_begin = vpb_digit_begin,
+ .send_digit_end = vpb_digit_end,
+ .call = vpb_call,
+ .hangup = vpb_hangup,
+ .answer = vpb_answer,
+ .read = vpb_read,
+ .read_stream = NULL,
+ .write = vpb_write,
+ .write_stream = NULL,
+ .send_text = NULL,
+ .send_image = NULL,
+ .send_html = NULL,
+ .exception = NULL,
+ .early_bridge = NULL,
+ .indicate = vpb_indicate,
+ .fixup = vpb_fixup,
+ .setoption = NULL,
+ .queryoption = NULL,
+ .transfer = NULL,
+ .write_video = NULL,
+ .write_text = NULL,
+ .func_channel_read = NULL,
+ .func_channel_write = NULL,
};
static struct ast_channel_tech vpb_tech_indicate = {
- type: "vpb",
- description: tdesc,
- capabilities: NULL,
- properties: 0,
- requester: vpb_request,
- requester_with_stream_topology: NULL,
- devicestate: NULL,
- presencestate: NULL,
- send_digit_begin: vpb_digit_begin,
- send_digit_end: vpb_digit_end,
- call: vpb_call,
- hangup: vpb_hangup,
- answer: vpb_answer,
- read: vpb_read,
- read_stream: NULL,
- write: vpb_write,
- write_stream: NULL,
- send_text: NULL,
- send_image: NULL,
- send_html: NULL,
- exception: NULL,
- early_bridge: NULL,
- indicate: NULL,
- fixup: vpb_fixup,
- setoption: NULL,
- queryoption: NULL,
- transfer: NULL,
- write_video: NULL,
- write_text: NULL,
- func_channel_read: NULL,
- func_channel_write: NULL,
+ .type = "vpb",
+ .description = tdesc,
+ .capabilities = NULL,
+ .properties = 0,
+ .requester = vpb_request,
+ .requester_with_stream_topology = NULL,
+ .devicestate = NULL,
+ .presencestate = NULL,
+ .send_digit_begin = vpb_digit_begin,
+ .send_digit_end = vpb_digit_end,
+ .call = vpb_call,
+ .hangup = vpb_hangup,
+ .answer = vpb_answer,
+ .read = vpb_read,
+ .read_stream = NULL,
+ .write = vpb_write,
+ .write_stream = NULL,
+ .send_text = NULL,
+ .send_image = NULL,
+ .send_html = NULL,
+ .exception = NULL,
+ .early_bridge = NULL,
+ .indicate = NULL,
+ .fixup = vpb_fixup,
+ .setoption = NULL,
+ .queryoption = NULL,
+ .transfer = NULL,
+ .write_video = NULL,
+ .write_text = NULL,
+ .func_channel_read = NULL,
+ .func_channel_write = NULL,
};
#if defined(VPB_NATIVE_BRIDGING)
diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c
index aa376f892..ce347dcd9 100644
--- a/channels/pjsip/dialplan_functions.c
+++ b/channels/pjsip/dialplan_functions.c
@@ -897,7 +897,7 @@ int pjsip_acf_channel_read(struct ast_channel *chan, const char *cmd, char *data
func_args.field = args.field;
func_args.buf = buf;
func_args.len = len;
- if (ast_sip_push_task_synchronous(func_args.session->serializer, read_pjsip, &func_args)) {
+ if (ast_sip_push_task_wait_serializer(func_args.session->serializer, read_pjsip, &func_args)) {
ast_log(LOG_WARNING, "Unable to read properties of channel %s: failed to push task\n", ast_channel_name(chan));
ao2_ref(func_args.session, -1);
return -1;
@@ -1219,7 +1219,7 @@ int pjsip_acf_media_offer_write(struct ast_channel *chan, const char *cmd, char
mdata.media_type = AST_MEDIA_TYPE_VIDEO;
}
- return ast_sip_push_task_synchronous(channel->session->serializer, media_offer_write_av, &mdata);
+ return ast_sip_push_task_wait_serializer(channel->session->serializer, media_offer_write_av, &mdata);
}
int pjsip_acf_dtmf_mode_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
@@ -1390,7 +1390,7 @@ int pjsip_acf_dtmf_mode_write(struct ast_channel *chan, const char *cmd, char *d
ast_channel_unlock(chan);
- return ast_sip_push_task_synchronous(channel->session->serializer, dtmf_mode_refresh_cb, &rdata);
+ return ast_sip_push_task_wait_serializer(channel->session->serializer, dtmf_mode_refresh_cb, &rdata);
}
static int refresh_write_cb(void *obj)
@@ -1438,5 +1438,5 @@ int pjsip_acf_session_refresh_write(struct ast_channel *chan, const char *cmd, c
rdata.method = AST_SIP_SESSION_REFRESH_METHOD_UPDATE;
}
- return ast_sip_push_task_synchronous(channel->session->serializer, refresh_write_cb, &rdata);
+ return ast_sip_push_task_wait_serializer(channel->session->serializer, refresh_write_cb, &rdata);
}
diff --git a/configs/samples/confbridge.conf.sample b/configs/samples/confbridge.conf.sample
index 4028593d2..8b276cdb8 100644
--- a/configs/samples/confbridge.conf.sample
+++ b/configs/samples/confbridge.conf.sample
@@ -239,6 +239,10 @@ type=bridge
; A REMB frame contains receiver estimated maximum bitrate information. By creating a combined
; frame and sending it to the sources of video the sender can be influenced on what bitrate
; they choose allowing a better experience for the receivers. This defaults to 0, or disabled.
+;remb_behavior=average ; How the combined REMB report for an SFU video bridge is constructed. If set to "average" then
+ ; the estimated maximum bitrate of each receiver is used to construct an average bitrate. If
+ ; set to "lowest" the lowest maximum bitrate is forwarded to the sender. If set to "highest"
+ ; the highest maximum bitrate is forwarded to the sender. This defaults to "average".
; All sounds in the conference are customizable using the bridge profile options below.
; Simply state the option followed by the filename or full path of the filename after
diff --git a/configure b/configure
index bc9ddfe05..a7657be94 100755
--- a/configure
+++ b/configure
@@ -13427,7 +13427,7 @@ else
$as_echo "yes" >&6; }
PBX_LIBEDIT=1
- LIBEDIT_INCLUDE="$LIBEDIT_CFLAGS"
+ LIBEDIT_INCLUDE=$(echo ${LIBEDIT_CFLAGS} | $SED -e "s|-std=c99||g")
LIBEDIT_LIB="$LIBEDIT_LIBS"
$as_echo "#define HAVE_LIBEDIT 1" >>confdefs.h
@@ -14101,7 +14101,7 @@ fi
if test ! "x${CONFIG_LIBXML2}" = xNo; then
LIBXML2_INCLUDE=$(${CONFIG_LIBXML2} --cflags)
- LIBXML2_INCLUDE=$(echo ${LIBXML2_INCLUDE} | $SED -e "s|-I|-I${LIBXML2_DIR}|g")
+ LIBXML2_INCLUDE=$(echo ${LIBXML2_INCLUDE} | $SED -e "s|-I|-I${LIBXML2_DIR}|g" -e "s|-std=c99||g")
LIBXML2_LIB=$(${CONFIG_LIBXML2} --libs)
LIBXML2_LIB=$(echo ${LIBXML2_LIB} | $SED -e "s|-L|-L${LIBXML2_DIR}|g")
@@ -20491,7 +20491,7 @@ else
$as_echo "yes" >&6; }
PBX_ILBC=1
- ILBC_INCLUDE="$ILBC_CFLAGS"
+ ILBC_INCLUDE=$(echo ${ILBC_CFLAGS} | $SED -e "s|-std=c99||g")
ILBC_LIB="$ILBC_LIBS"
$as_echo "#define HAVE_ILBC 1" >>confdefs.h
@@ -22629,7 +22629,7 @@ fi
if test ! "x${CONFIG_MYSQLCLIENT}" = xNo; then
MYSQLCLIENT_INCLUDE=$(${CONFIG_MYSQLCLIENT} --cflags)
- MYSQLCLIENT_INCLUDE=$(echo ${MYSQLCLIENT_INCLUDE} | $SED -e "s|-I|-I${MYSQLCLIENT_DIR}|g")
+ MYSQLCLIENT_INCLUDE=$(echo ${MYSQLCLIENT_INCLUDE} | $SED -e "s|-I|-I${MYSQLCLIENT_DIR}|g" -e "s|-std=c99||g")
MYSQLCLIENT_LIB=$(${CONFIG_MYSQLCLIENT} --libs)
MYSQLCLIENT_LIB=$(echo ${MYSQLCLIENT_LIB} | $SED -e "s|-L|-L${MYSQLCLIENT_DIR}|g")
@@ -22846,7 +22846,7 @@ fi
if test ! "x${CONFIG_NEON}" = xNo; then
NEON_INCLUDE=$(${CONFIG_NEON} --cflags)
- NEON_INCLUDE=$(echo ${NEON_INCLUDE} | $SED -e "s|-I|-I${NEON_DIR}|g")
+ NEON_INCLUDE=$(echo ${NEON_INCLUDE} | $SED -e "s|-I|-I${NEON_DIR}|g" -e "s|-std=c99||g")
NEON_LIB=$(${CONFIG_NEON} --libs)
NEON_LIB=$(echo ${NEON_LIB} | $SED -e "s|-L|-L${NEON_DIR}|g")
@@ -22966,7 +22966,7 @@ fi
if test ! "x${CONFIG_NEON29}" = xNo; then
NEON29_INCLUDE=$(${CONFIG_NEON29} --cflags)
- NEON29_INCLUDE=$(echo ${NEON29_INCLUDE} | $SED -e "s|-I|-I${NEON29_DIR}|g")
+ NEON29_INCLUDE=$(echo ${NEON29_INCLUDE} | $SED -e "s|-I|-I${NEON29_DIR}|g" -e "s|-std=c99||g")
NEON29_LIB=$(${CONFIG_NEON29} --libs)
NEON29_LIB=$(echo ${NEON29_LIB} | $SED -e "s|-L|-L${NEON29_DIR}|g")
@@ -23110,7 +23110,7 @@ fi
if test ! "x${CONFIG_NETSNMP}" = xNo; then
NETSNMP_INCLUDE=$(${CONFIG_NETSNMP} --cflags)
- NETSNMP_INCLUDE=$(echo ${NETSNMP_INCLUDE} | $SED -e "s|-I|-I${NETSNMP_DIR}|g")
+ NETSNMP_INCLUDE=$(echo ${NETSNMP_INCLUDE} | $SED -e "s|-I|-I${NETSNMP_DIR}|g" -e "s|-std=c99||g")
NETSNMP_LIB=$(${CONFIG_NETSNMP} --agent-libs)
NETSNMP_LIB=$(echo ${NETSNMP_LIB} | $SED -e "s|-L|-L${NETSNMP_DIR}|g")
@@ -24596,7 +24596,7 @@ else
$as_echo "yes" >&6; }
PBX_PJPROJECT=1
- PJPROJECT_INCLUDE="$PJPROJECT_CFLAGS"
+ PJPROJECT_INCLUDE=$(echo ${PJPROJECT_CFLAGS} | $SED -e "s|-std=c99||g")
PJPROJECT_LIB="$PJPROJECT_LIBS"
$as_echo "#define HAVE_PJPROJECT 1" >>confdefs.h
@@ -25650,7 +25650,7 @@ else
$as_echo "yes" >&6; }
PBX_PYTHONDEV=1
- PYTHONDEV_INCLUDE="$PYTHONDEV_CFLAGS"
+ PYTHONDEV_INCLUDE=$(echo ${PYTHONDEV_CFLAGS} | $SED -e "s|-std=c99||g")
PYTHONDEV_LIB="$PYTHONDEV_LIBS"
$as_echo "#define HAVE_PYTHONDEV 1" >>confdefs.h
@@ -25836,7 +25836,7 @@ else
$as_echo "yes" >&6; }
PBX_PORTAUDIO=1
- PORTAUDIO_INCLUDE="$PORTAUDIO_CFLAGS"
+ PORTAUDIO_INCLUDE=$(echo ${PORTAUDIO_CFLAGS} | $SED -e "s|-std=c99||g")
PORTAUDIO_LIB="$PORTAUDIO_LIBS"
$as_echo "#define HAVE_PORTAUDIO 1" >>confdefs.h
@@ -32140,7 +32140,7 @@ else
$as_echo "yes" >&6; }
PBX_GMIME=1
- GMIME_INCLUDE="$GMIME_CFLAGS"
+ GMIME_INCLUDE=$(echo ${GMIME_CFLAGS} | $SED -e "s|-std=c99||g")
GMIME_LIB="$GMIME_LIBS"
$as_echo "#define HAVE_GMIME 1" >>confdefs.h
@@ -33049,7 +33049,7 @@ fi
if test ! "x${CONFIG_SDL}" = xNo; then
SDL_INCLUDE=$(${CONFIG_SDL} --cflags)
- SDL_INCLUDE=$(echo ${SDL_INCLUDE} | $SED -e "s|-I|-I${SDL_DIR}|g")
+ SDL_INCLUDE=$(echo ${SDL_INCLUDE} | $SED -e "s|-I|-I${SDL_DIR}|g" -e "s|-std=c99||g")
SDL_LIB=$(${CONFIG_SDL} --libs)
SDL_LIB=$(echo ${SDL_LIB} | $SED -e "s|-L|-L${SDL_DIR}|g")
@@ -33577,7 +33577,7 @@ else
$as_echo "yes" >&6; }
PBX_GTK2=1
- GTK2_INCLUDE="$GTK2_CFLAGS"
+ GTK2_INCLUDE=$(echo ${GTK2_CFLAGS} | $SED -e "s|-std=c99||g")
GTK2_LIB="$GTK2_LIBS"
$as_echo "#define HAVE_GTK2 1" >>confdefs.h
@@ -33688,7 +33688,7 @@ else
$as_echo "yes" >&6; }
PBX_SYSTEMD=1
- SYSTEMD_INCLUDE="$SYSTEMD_CFLAGS"
+ SYSTEMD_INCLUDE=$(echo ${SYSTEMD_CFLAGS} | $SED -e "s|-std=c99||g")
SYSTEMD_LIB="$SYSTEMD_LIBS"
$as_echo "#define HAVE_SYSTEMD 1" >>confdefs.h
diff --git a/contrib/scripts/install_prereq b/contrib/scripts/install_prereq
index 3ac7a0a1f..dfeb36f2c 100755
--- a/contrib/scripts/install_prereq
+++ b/contrib/scripts/install_prereq
@@ -146,6 +146,22 @@ PACKAGES_FBSD="$PACKAGES_FBSD wget subversion"
# Asterisk: for ./configure --with-pjproject-bundled:
PACKAGES_FBSD="$PACKAGES_FBSD bzip2 patch python"
+# Basic build system:
+PACKAGES_DBSD="gmake pkgconf"
+# Asterisk: basic requirements:
+PACKAGES_DBSD="$PACKAGES_DBSD libedit jansson e2fsprogs-libuuid sqlite3 libxml2"
+# Asterisk: for addons:
+PACKAGES_DBSD="$PACKAGES_DBSD speex speexdsp libogg libvorbis alsa-lib portaudio curl xmlstarlet bison flex"
+PACKAGES_DBSD="$PACKAGES_DBSD postgresql10-client unixODBC neon gmime26 lua52 uriparser libxslt libressl"
+PACKAGES_DBSD="$PACKAGES_DBSD mariadb101-client radcli freetds"
+PACKAGES_DBSD="$PACKAGES_DBSD net-snmp iksemel corosync newt popt libical spandsp"
+PACKAGES_DBSD="$PACKAGES_DBSD cclient binutils libsrtp gsm libilbc doxygen graphviz libzip openldap-client libhoard"
+PACKAGES_DBSD="$PACKAGES_DBSD codec2 fftw3 libsndfile unbound"
+# Asterisk: for the unpackaged below:
+PACKAGES_DBSD="$PACKAGES_DBSD wget subversion"
+# Asterisk: for ./configure --with-pjproject-bundled:
+PACKAGES_DBSD="$PACKAGES_DBSD bzip2 patch python"
+
KVERS=`uname -r`
JANSSON_VER=2.11
@@ -302,6 +318,13 @@ handle_fbsd() {
fi
}
+handle_dbsd() {
+ extra_packs=`check_installed_fpkgs $PACKAGES_DBSD`
+ if [ x"$extra_packs" != "x" ] ; then
+ $testcmd pkg install -y $extra_packs
+ fi
+}
+
handle_SUSE() {
extra_packs=`check_installed_zypper $PACKAGES_SUSE`
if [ x"$extra_packs" != "x" ] ; then
@@ -380,7 +403,7 @@ OS=`uname -s`
unsupported_distro=''
# A number of distributions we don't (yet?) support.
-if [ "$OS" != 'Linux' -a "$OS" != 'NetBSD' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' ]; then
+if [ "$OS" != 'Linux' -a "$OS" != 'NetBSD' -a "$OS" != 'OpenBSD' -a "$OS" != 'FreeBSD' -a "$OS" != 'DragonFly' ]; then
echo >&2 "$0: Your OS ($OS) is currently not supported. Aborting."
exit 1
fi
@@ -427,6 +450,8 @@ elif [ "$OS" = 'OpenBSD' ]; then
handle_obsd
elif [ "$OS" = 'FreeBSD' ]; then
handle_fbsd
+elif [ "$OS" = 'DragonFly' ]; then
+ handle_dbsd
fi
if ! in_test_mode; then
diff --git a/contrib/scripts/refcounter.py b/contrib/scripts/refcounter.py
index 1f4b37517..de3cda051 100755
--- a/contrib/scripts/refcounter.py
+++ b/contrib/scripts/refcounter.py
@@ -18,6 +18,7 @@
Matt Jordan <mjordan@digium.com>
"""
+from __future__ import print_function
import sys
import os
@@ -35,8 +36,8 @@ def parse_line(line):
"""
tokens = line.strip().split(',', 7)
if len(tokens) < 8:
- print "ERROR: ref debug line '%s' contains fewer tokens than " \
- "expected: %d" % (line.strip(), len(tokens))
+ print("ERROR: ref debug line '%s' contains fewer tokens than "
+ "expected: %d" % (line.strip(), len(tokens)))
return None
processed_line = {'addr': tokens[0],
@@ -142,7 +143,7 @@ def process_file(options):
del current_objects[obj]
if options.leaks:
- for key, lines in current_objects.iteritems():
+ for (key, lines) in current_objects.items():
leaked_objects.append((key, lines))
return (finished_objects, invalid_objects, leaked_objects, skewed_objects)
@@ -156,13 +157,13 @@ def print_objects(objects, prefix=""):
this object
"""
- print "======== %s Objects ========" % prefix
- print "\n"
+ print("======== %s Objects ========" % prefix)
+ print("\n")
for obj in objects:
- print "==== %s Object %s history ====" % (prefix, obj[0])
+ print("==== %s Object %s history ====" % (prefix, obj[0]))
for line in obj[1]['log']:
- print line
- print "\n"
+ print(line)
+ print("\n")
def main(argv=None):
@@ -198,11 +199,11 @@ def main(argv=None):
if not options.invalid and not options.leaks and not options.normal \
and not options.skewed:
- print >>sys.stderr, "All options disabled"
+ print("All options disabled", file=sys.stderr)
return -1
if not os.path.isfile(options.filepath):
- print >>sys.stderr, "File not found: %s" % options.filepath
+ print("File not found: %s" % options.filepath, file=sys.stderr)
return -1
try:
@@ -227,7 +228,7 @@ def main(argv=None):
print_objects(finished_objects, "Finalized")
except (KeyboardInterrupt, SystemExit, IOError):
- print >>sys.stderr, "File processing cancelled"
+ print("File processing cancelled", file=sys.stderr)
return -1
return ret_code
diff --git a/contrib/scripts/spandspflow2pcap.py b/contrib/scripts/spandspflow2pcap.py
index a6546b693..7c403f105 100755
--- a/contrib/scripts/spandspflow2pcap.py
+++ b/contrib/scripts/spandspflow2pcap.py
@@ -119,7 +119,7 @@ class FaxPcap(object):
else:
self.date += timedelta(microseconds=9000)
- print seqno, '\t', self.date + self.dateoff
+ print(seqno, '\t', self.date + self.dateoff)
# Make packet.
packet, prev_data = self.data2packet(self.date + self.dateoff,
diff --git a/contrib/scripts/voicemailpwcheck.py b/contrib/scripts/voicemailpwcheck.py
index d7a66d4b9..452255c35 100755
--- a/contrib/scripts/voicemailpwcheck.py
+++ b/contrib/scripts/voicemailpwcheck.py
@@ -46,20 +46,20 @@ mailbox, context, old_pw, new_pw = sys.argv[1:5]
# Enforce a password length of at least 6 characters
if len(new_pw) < REQUIRED_LENGTH:
- print "INVALID: Password is too short (%d) - must be at least %d" % \
- (len(new_pw), REQUIRED_LENGTH)
+ print("INVALID: Password is too short (%d) - must be at least %d" % \
+ (len(new_pw), REQUIRED_LENGTH))
sys.exit(0)
for regex, error in REGEX_BLACKLIST:
if re.search(regex, new_pw):
- print "INVALID: %s" % error
+ print("INVALID: %s" % error)
sys.exit(0)
for pw in PW_BLACKLIST:
if new_pw.find(pw) != -1:
- print "INVALID: %s is forbidden in a password" % pw
+ print("INVALID: %s is forbidden in a password" % pw)
sys.exit(0)
-print "VALID"
+print("VALID")
sys.exit(0)
diff --git a/doc/.gitignore b/doc/.gitignore
index 3461c58c5..49bfe4293 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -1,4 +1,5 @@
core-en_US.xml
+full-en_US.xml
rest-api
api
asterisk-ng-doxygen
diff --git a/formats/format_pcm.c b/formats/format_pcm.c
index 35612c964..4e846d7cf 100644
--- a/formats/format_pcm.c
+++ b/formats/format_pcm.c
@@ -91,10 +91,7 @@ static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
return NULL;
}
s->fr.datalen = res;
- if (ast_format_cmp(s->fmt->format, ast_format_g722) == AST_FORMAT_CMP_EQUAL)
- *whennext = s->fr.samples = res * 2;
- else
- *whennext = s->fr.samples = res;
+ *whennext = s->fr.samples = res;
return &s->fr;
}
@@ -410,16 +407,11 @@ static int au_rewrite(struct ast_filestream *s, const char *comment)
static int au_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{
off_t min, max, cur;
- long offset = 0, bytes;
+ long offset = 0;
struct au_desc *desc = fs->_private;
min = desc->hdr_size;
- if (ast_format_cmp(fs->fmt->format, ast_format_g722) == AST_FORMAT_CMP_EQUAL)
- bytes = sample_offset / 2;
- else
- bytes = sample_offset;
-
if ((cur = ftello(fs->f)) < 0) {
ast_log(AST_LOG_WARNING, "Unable to determine current position in au filestream %p: %s\n", fs, strerror(errno));
return -1;
@@ -436,11 +428,11 @@ static int au_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
}
if (whence == SEEK_SET)
- offset = bytes + min;
+ offset = sample_offset + min;
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = bytes + cur;
+ offset = sample_offset + cur;
else if (whence == SEEK_END)
- offset = max - bytes;
+ offset = max - sample_offset;
if (whence != SEEK_FORCECUR) {
offset = (offset > max) ? max : offset;
@@ -479,6 +471,23 @@ static off_t au_tell(struct ast_filestream *fs)
return offset - desc->hdr_size;
}
+static struct ast_frame *g722_read(struct ast_filestream *s, int *whennext)
+{
+ struct ast_frame *f = pcm_read(s, whennext);
+ *whennext = s->fr.samples = (*whennext * 2);
+ return f;
+}
+
+static int g722_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
+{
+ return pcm_seek(fs, sample_offset / 2, whence);
+}
+
+static off_t g722_tell(struct ast_filestream *fs)
+{
+ return pcm_tell(fs) * 2;
+}
+
static struct ast_format_def alaw_f = {
.name = "alaw",
.exts = "alaw|al|alw",
@@ -510,10 +519,10 @@ static struct ast_format_def g722_f = {
.name = "g722",
.exts = "g722",
.write = pcm_write,
- .seek = pcm_seek,
+ .seek = g722_seek,
.trunc = pcm_trunc,
- .tell = pcm_tell,
- .read = pcm_read,
+ .tell = g722_tell,
+ .read = g722_read,
.buf_size = (BUF_SIZE * 2) + AST_FRIENDLY_OFFSET,
};
diff --git a/include/asterisk/bridge.h b/include/asterisk/bridge.h
index b23255844..3584085af 100644
--- a/include/asterisk/bridge.h
+++ b/include/asterisk/bridge.h
@@ -126,6 +126,24 @@ struct ast_bridge_video_talker_src_data {
struct ast_channel *chan_old_vsrc;
};
+/*! \brief REMB report behaviors */
+enum ast_bridge_video_sfu_remb_behavior {
+ /*! The average of all reports is sent to the sender */
+ AST_BRIDGE_VIDEO_SFU_REMB_AVERAGE = 0,
+ /*! The lowest reported bitrate is forwarded to the sender */
+ AST_BRIDGE_VIDEO_SFU_REMB_LOWEST,
+ /*! The highest reported bitrate is forwarded to the sender */
+ AST_BRIDGE_VIDEO_SFU_REMB_HIGHEST,
+};
+
+/*! \brief This is used for selective forwarding unit configuration */
+struct ast_bridge_video_sfu_data {
+ /*! The interval at which a REMB report is generated and sent */
+ unsigned int remb_send_interval;
+ /*! How the combined REMB report is generated */
+ enum ast_bridge_video_sfu_remb_behavior remb_behavior;
+};
+
/*! \brief Data structure that defines a video source mode */
struct ast_bridge_video_mode {
enum ast_bridge_video_mode_type mode;
@@ -133,9 +151,10 @@ struct ast_bridge_video_mode {
union {
struct ast_bridge_video_single_src_data single_src_data;
struct ast_bridge_video_talker_src_data talker_src_data;
+ struct ast_bridge_video_sfu_data sfu_data;
} mode_data;
+ /*! The minimum interval between video updates */
unsigned int video_update_discard;
- unsigned int remb_send_interval;
};
/*!
@@ -917,10 +936,22 @@ void ast_bridge_set_video_update_discard(struct ast_bridge *bridge, unsigned int
*
* \param bridge Bridge to set the REMB send interval on
* \param remb_send_interval The REMB send interval
+ *
+ * \note This can only be called when the bridge has been set to the SFU video mode.
*/
void ast_bridge_set_remb_send_interval(struct ast_bridge *bridge, unsigned int remb_send_interval);
/*!
+ * \brief Set the REMB report generation behavior on a bridge
+ *
+ * \param bridge Bridge to set the REMB behavior on
+ * \param behavior How REMB reports are generated
+ *
+ * \note This can only be called when the bridge has been set to the SFU video mode.
+ */
+void ast_brige_set_remb_behavior(struct ast_bridge *bridge, enum ast_bridge_video_sfu_remb_behavior behavior);
+
+/*!
* \brief Update information about talker energy for talker src video mode.
*/
void ast_bridge_update_talker_src_video_mode(struct ast_bridge *bridge, struct ast_channel *chan, int talker_energy, int is_keyfame);
@@ -954,6 +985,17 @@ void ast_bridge_remove_video_src(struct ast_bridge *bridge, struct ast_channel *
*/
const char *ast_bridge_video_mode_to_string(enum ast_bridge_video_mode_type video_mode);
+/*!
+ * \brief Acquire the channel's bridge for transfer purposes.
+ * \since 13.21.0
+ *
+ * \param chan Channel involved in a transfer.
+ *
+ * \return The bridge the channel is in or NULL if it either isn't
+ * in a bridge or should not be considered to be in a bridge.
+ */
+struct ast_bridge *ast_bridge_transfer_acquire_bridge(struct ast_channel *chan);
+
enum ast_transfer_result {
/*! The transfer completed successfully */
AST_BRIDGE_TRANSFER_SUCCESS,
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 26439986b..d2ae39baf 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -258,6 +258,14 @@ struct ast_sip_contact {
AST_STRING_FIELD(user_agent);
/*! The name of the aor this contact belongs to */
AST_STRING_FIELD(aor);
+ /*! Asterisk Server name */
+ AST_STRING_FIELD(reg_server);
+ /*! IP-address of the Via header in REGISTER request */
+ AST_STRING_FIELD(via_addr);
+ /*! Content of the Call-ID header in REGISTER request */
+ AST_STRING_FIELD(call_id);
+ /*! The name of the endpoint that added the contact */
+ AST_STRING_FIELD(endpoint_name);
);
/*! Absolute time that this contact is no longer valid after */
struct timeval expiration_time;
@@ -269,16 +277,8 @@ struct ast_sip_contact {
double qualify_timeout;
/*! Endpoint that added the contact, only available in observers */
struct ast_sip_endpoint *endpoint;
- /*! Asterisk Server name */
- AST_STRING_FIELD_EXTENDED(reg_server);
- /*! IP-address of the Via header in REGISTER request */
- AST_STRING_FIELD_EXTENDED(via_addr);
- /* Port of the Via header in REGISTER request */
+ /*! Port of the Via header in REGISTER request */
int via_port;
- /*! Content of the Call-ID header in REGISTER request */
- AST_STRING_FIELD_EXTENDED(call_id);
- /*! The name of the endpoint that added the contact */
- AST_STRING_FIELD_EXTENDED(endpoint_name);
/*! If true delete the contact on Asterisk restart/boot */
int prune_on_boot;
};
@@ -751,6 +751,8 @@ struct ast_sip_endpoint {
AST_STRING_FIELD(message_context);
/*! Accountcode to auto-set on channels */
AST_STRING_FIELD(accountcode);
+ /*! If set, we'll push incoming MWI NOTIFYs to stasis using this mailbox */
+ AST_STRING_FIELD(incoming_mwi_mailbox);
);
/*! Configuration for extensions */
struct ast_sip_endpoint_extensions extensions;
@@ -812,8 +814,6 @@ struct ast_sip_endpoint {
unsigned int refer_blind_progress;
/*! Whether to notifies dialog-info 'early' on INUSE && RINGING state */
unsigned int notify_early_inuse_ringing;
- /*! If set, we'll push incoming MWI NOTIFYs to stasis using this mailbox */
- AST_STRING_FIELD_EXTENDED(incoming_mwi_mailbox);
};
/*! URI parameter for symmetric transport */
@@ -1407,7 +1407,7 @@ struct ast_sip_endpoint *ast_sip_get_artificial_endpoint(void);
* the next item on the SIP socket(s) can be serviced. On incoming messages,
* Asterisk automatically will push the request to a servant thread. When your
* module callback is called, processing will already be in a servant. However,
- * for other PSJIP events, such as transaction state changes due to timer
+ * for other PJSIP events, such as transaction state changes due to timer
* expirations, your module will be called into from a PJSIP thread. If you
* are called into from a PJSIP thread, then you should push whatever processing
* is needed to a servant as soon as possible. You can discern if you are currently
@@ -1543,28 +1543,92 @@ struct ast_sip_endpoint *ast_sip_dialog_get_endpoint(pjsip_dialog *dlg);
int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
/*!
- * \brief Push a task to SIP servants and wait for it to complete
+ * \brief Push a task to SIP servants and wait for it to complete.
*
- * Like \ref ast_sip_push_task except that it blocks until the task completes.
+ * Like \ref ast_sip_push_task except that it blocks until the task
+ * completes. If the current thread is a SIP servant thread then the
+ * task executes immediately. Otherwise, the specified serializer
+ * executes the task and the current thread waits for it to complete.
*
- * \warning \b Never use this function in a SIP servant thread. This can potentially
- * cause a deadlock. If you are in a SIP servant thread, just call your function
- * in-line.
+ * \note PJPROJECT callbacks tend to have locks already held when
+ * called.
*
- * \warning \b Never hold locks that may be acquired by a SIP servant thread when
- * calling this function. Doing so may cause a deadlock if all SIP servant threads
- * are blocked waiting to acquire the lock while the thread holding the lock is
- * waiting for a free SIP servant thread.
+ * \warning \b Never hold locks that may be acquired by a SIP servant
+ * thread when calling this function. Doing so may cause a deadlock
+ * if all SIP servant threads are blocked waiting to acquire the lock
+ * while the thread holding the lock is waiting for a free SIP servant
+ * thread.
*
- * \param serializer The SIP serializer to which the task belongs. May be NULL.
+ * \warning \b Use of this function in an ao2 destructor callback is a
+ * bad idea. You don't have control over which thread executes the
+ * destructor. Attempting to shift execution to another thread with
+ * this function is likely to cause deadlock.
+ *
+ * \param serializer The SIP serializer to execute the task if the
+ * current thread is not a SIP servant. NULL if any of the default
+ * serializers can be used.
* \param sip_task The task to execute
* \param task_data The parameter to pass to the task when it executes
- * \retval 0 Success
- * \retval -1 Failure
+ *
+ * \note The sip_task() return value may need to be distinguished from
+ * the failure to push the task.
+ *
+ * \return sip_task() return value on success.
+ * \retval -1 Failure to push the task.
+ */
+int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
+
+/*!
+ * \brief Push a task to SIP servants and wait for it to complete.
+ * \deprecated Replaced with ast_sip_push_task_wait_servant().
*/
int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
/*!
+ * \brief Push a task to the serializer and wait for it to complete.
+ *
+ * Like \ref ast_sip_push_task except that it blocks until the task is
+ * completed by the specified serializer. If the specified serializer
+ * is the current thread then the task executes immediately.
+ *
+ * \note PJPROJECT callbacks tend to have locks already held when
+ * called.
+ *
+ * \warning \b Never hold locks that may be acquired by a SIP servant
+ * thread when calling this function. Doing so may cause a deadlock
+ * if all SIP servant threads are blocked waiting to acquire the lock
+ * while the thread holding the lock is waiting for a free SIP servant
+ * thread for the serializer to execute in.
+ *
+ * \warning \b Never hold locks that may be acquired by the serializer
+ * when calling this function. Doing so will cause a deadlock.
+ *
+ * \warning \b Never use this function in the pjsip monitor thread (It
+ * is a SIP servant thread). This is likely to cause a deadlock.
+ *
+ * \warning \b Use of this function in an ao2 destructor callback is a
+ * bad idea. You don't have control over which thread executes the
+ * destructor. Attempting to shift execution to another thread with
+ * this function is likely to cause deadlock.
+ *
+ * \param serializer The SIP serializer to execute the task. NULL if
+ * any of the default serializers can be used.
+ * \param sip_task The task to execute
+ * \param task_data The parameter to pass to the task when it executes
+ *
+ * \note It is generally better to call
+ * ast_sip_push_task_wait_servant() if you pass NULL for the
+ * serializer parameter.
+ *
+ * \note The sip_task() return value may need to be distinguished from
+ * the failure to push the task.
+ *
+ * \return sip_task() return value on success.
+ * \retval -1 Failure to push the task.
+ */
+int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
+
+/*!
* \brief Determine if the current thread is a SIP servant thread
*
* \retval 0 This is not a SIP servant thread
@@ -1588,13 +1652,13 @@ enum ast_sip_scheduler_task_flags {
/*!
* Run at a fixed interval.
- * Stop scheduling if the callback returns 0.
+ * Stop scheduling if the callback returns <= 0.
* Any other value is ignored.
*/
AST_SIP_SCHED_TASK_FIXED = (0 << 0),
/*!
* Run at a variable interval.
- * Stop scheduling if the callback returns 0.
+ * Stop scheduling if the callback returns <= 0.
* Any other return value is used as the new interval.
*/
AST_SIP_SCHED_TASK_VARIABLE = (1 << 0),
@@ -1620,16 +1684,23 @@ enum ast_sip_scheduler_task_flags {
*/
AST_SIP_SCHED_TASK_DATA_FREE = ( 1 << 3 ),
- /*! \brief AST_SIP_SCHED_TASK_PERIODIC
- * The task is scheduled at multiples of interval
+ /*!
+ * \brief The task is scheduled at multiples of interval
* \see Interval
*/
AST_SIP_SCHED_TASK_PERIODIC = (0 << 4),
- /*! \brief AST_SIP_SCHED_TASK_DELAY
- * The next invocation of the task is at last finish + interval
+ /*!
+ * \brief The next invocation of the task is at last finish + interval
* \see Interval
*/
AST_SIP_SCHED_TASK_DELAY = (1 << 4),
+ /*!
+ * \brief The scheduled task's events are tracked in the debug log.
+ * \details
+ * Schedule events such as scheduling, running, rescheduling, canceling,
+ * and destroying are logged about the task.
+ */
+ AST_SIP_SCHED_TASK_TRACK = (1 << 5),
};
/*!
@@ -1673,7 +1744,7 @@ struct ast_sip_sched_task;
*
*/
struct ast_sip_sched_task *ast_sip_schedule_task(struct ast_taskprocessor *serializer,
- int interval, ast_sip_task sip_task, char *name, void *task_data,
+ int interval, ast_sip_task sip_task, const char *name, void *task_data,
enum ast_sip_scheduler_task_flags flags);
/*!
diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h
index 8f044ce17..3426b2a1e 100644
--- a/include/asterisk/rtp_engine.h
+++ b/include/asterisk/rtp_engine.h
@@ -292,10 +292,14 @@ struct ast_rtp_payload_type {
#define AST_RTP_RTCP_SR 200
/*! Receiver Report */
#define AST_RTP_RTCP_RR 201
+/*! Transport Layer Feed Back (From RFC4585 also RFC5104) */
+#define AST_RTP_RTCP_RTPFB 205
/*! Payload Specific Feed Back (From RFC4585 also RFC5104) */
-#define AST_RTP_RTCP_PSFB 206
+#define AST_RTP_RTCP_PSFB 206
/* Common RTCP feedback message types */
+/*! Generic NACK (From RFC4585 also RFC5104) */
+#define AST_RTP_RTCP_FMT_NACK 1
/*! Picture loss indication (From RFC4585) */
#define AST_RTP_RTCP_FMT_PLI 1
/*! Full INTRA-frame Request (From RFC5104) */
diff --git a/include/asterisk/sdp.h b/include/asterisk/sdp.h
deleted file mode 100644
index 768469544..000000000
--- a/include/asterisk/sdp.h
+++ /dev/null
@@ -1,703 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/* NOTE: It is unlikely that you need to include this file. You probably will only need
- * this if you are an SDP translator, or if you are an inner part of the SDP API
- */
-
-#ifndef _SDP_PRIV_H
-#define _SDP_PRIV_H
-
-#include "asterisk/vector.h"
-#include "asterisk/format.h"
-#include "asterisk/sdp_state.h"
-#include "asterisk/stream.h"
-
-/*!
- * \brief Structure representing an SDP Attribute
- */
-struct ast_sdp_a_line {
- /*! Attribute name */
- char *name;
- /*! Attribute value. For attributes that have no value, this will be an empty string */
- char *value;
-};
-
-/*!
- * \brief A collection of SDP Attributes
- */
-AST_VECTOR(ast_sdp_a_lines, struct ast_sdp_a_line *);
-
-/*!
- * \brief Structure representing an SDP Connection
- */
-struct ast_sdp_c_line {
- /* IP family string (e.g. IP4 or IP6) */
- char *address_type;
- /* Connection address. Can be an IP address or FQDN */
- char *address;
-};
-
-/*!
- * \brief Structre representing SDP Media Payloads
- */
-struct ast_sdp_payload {
- /* Media format description */
- char *fmt;
-};
-
-/*!
- * \brief A collection of SDP Media Payloads
- */
-AST_VECTOR(ast_sdp_payloads, struct ast_sdp_payload *);
-
-/*!
- * \brief Structure representing an SDP Media Stream
- *
- * This contains both the m line, as well as its
- * constituent a lines.
- */
-struct ast_sdp_m_line {
- /*! Media type (e.g. "audio" or "video") */
- char *type;
- /*! RTP profile string (e.g. "RTP/AVP") */
- char *proto;
- /*! Port number in m line */
- uint16_t port;
- /*! Number of ports specified in m line */
- uint16_t port_count;
- /*! RTP payloads */
- struct ast_sdp_payloads *payloads;
- /*! Connection information for this media stream */
- struct ast_sdp_c_line *c_line;
- /*! The attributes for this media stream */
- struct ast_sdp_a_lines *a_lines;
-};
-
-/*!
- * \brief A collection of SDP Media Streams
- */
-AST_VECTOR(ast_sdp_m_lines, struct ast_sdp_m_line *);
-
-/*!
- * \brief Structure representing an SDP Origin
- */
-struct ast_sdp_o_line {
- /*! Origin user name */
- char *username;
- /*! Origin id */
- uint64_t session_id;
- /*! Origin version */
- uint64_t session_version;
- /*! Origin IP address type (e.g. "IP4" or "IP6") */
- char *address_type;
- /*! Origin address. Can be an IP address or FQDN */
- char *address;
-};
-
-/*!
- * \brief Structure representing an SDP Session Name
- */
-struct ast_sdp_s_line {
- /* Session Name */
- char *session_name;
-};
-
-/*!
- * \brief Structure representing SDP Timing
- */
-struct ast_sdp_t_line {
- /*! Session start time */
- uint64_t start_time;
- /*! Session end time */
- uint64_t stop_time;
-};
-
-/*!
- * \brief An SDP
- */
-struct ast_sdp {
- /*! SDP Origin line */
- struct ast_sdp_o_line *o_line;
- /*! SDP Session name */
- struct ast_sdp_s_line *s_line;
- /*! SDP top-level connection information */
- struct ast_sdp_c_line *c_line;
- /*! SDP timing information */
- struct ast_sdp_t_line *t_line;
- /*! SDP top-level attributes */
- struct ast_sdp_a_lines *a_lines;
- /*! SDP media streams */
- struct ast_sdp_m_lines *m_lines;
-};
-
-/*!
- * \brief A structure representing an SDP rtpmap attribute
- */
-struct ast_sdp_rtpmap {
- /*! The RTP payload number for the rtpmap */
- int payload;
- /*! The Name of the codec */
- char *encoding_name;
- /*! The clock rate of the codec */
- int clock_rate;
- /*! Optional encoding parameters */
- char *encoding_parameters;
- /*! Area where strings are stored */
- char buf[0];
-};
-
-/*!
- * \brief Free an SDP Attribute
- *
- * \param a_line The attribute to free
- *
- * \since 15
- */
-void ast_sdp_a_free(struct ast_sdp_a_line *a_line);
-
-/*!
- * \brief Free an SDP Attribute collection
- *
- * \param a_lines The attribute collection to free
- *
- * \since 15
- */
-void ast_sdp_a_lines_free(struct ast_sdp_a_lines *a_lines);
-
-/*!
- * \brief Free SDP Connection Data
- *
- * \param c_line The connection data to free
- *
- * \since 15
- */
-void ast_sdp_c_free(struct ast_sdp_c_line *c_line);
-
-/*!
- * \brief Free an SDP Media Description Payload
- *
- * \param payload The payload to free
- *
- * \since 15
- */
-void ast_sdp_payload_free(struct ast_sdp_payload *payload);
-
-/*!
- * \brief Free an SDP Media Description Payload collection
- *
- * \param payloads collection to free
- *
- * \since 15
- */
-void ast_sdp_payloads_free(struct ast_sdp_payloads *payloads);
-
-/*!
- * \brief Free an SDP Media Description
- * Frees the media description and all resources it contains
- *
- * \param m_line The media description to free
- *
- * \since 15
- */
-void ast_sdp_m_free(struct ast_sdp_m_line *m_line);
-
-/*!
- * \brief Free an SDP Media Description collection
- *
- * \param m_lines The collection description to free
- *
- * \since 15
- */
-void ast_sdp_m_lines_free(struct ast_sdp_m_lines *m_lines);
-
-/*!
- * \brief Free an SDP Origin
- *
- * \param o_line The origin description to free
- *
- * \since 15
- */
-void ast_sdp_o_free(struct ast_sdp_o_line *o_line);
-
-/*!
- * \brief Free an SDP Session
- *
- * \param s_line The session to free
- *
- * \since 15
- */
-void ast_sdp_s_free(struct ast_sdp_s_line *s_line);
-
-/*!
- * \brief Free SDP Timing
- *
- * \param t_line The timing description to free
- *
- * \since 15
- */
-void ast_sdp_t_free(struct ast_sdp_t_line *t_line);
-
-/*!
- * \brief Allocate an SDP Attribute
- *
- * \param name Attribute Name
- * \param value Attribute Name
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_a_line *ast_sdp_a_alloc(const char *name, const char *value);
-
-/*!
- * \brief Allocate an SDP Connection
- *
- * \param family Family ("IN", etc)
- * \param addr Address
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_c_line *ast_sdp_c_alloc(const char *family, const char *addr);
-
-/*!
- * \brief Allocate an SDP Media Description Payload
- *
- * \param fmt The media format description
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_payload *ast_sdp_payload_alloc(const char *fmt);
-
-/*!
- * \brief Allocate an SDP Media Description
- *
- * \param type ("audio", "video", etc)
- * \param port Starting port
- * \param port_count Port pairs to allocate
- * \param proto ("RTP/AVP", "RTP/SAVP", "udp")
- * \param c_line Connection to add. May be NULL
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_m_line *ast_sdp_m_alloc(const char *type, uint16_t port,
- uint16_t port_count, const char *proto, struct ast_sdp_c_line *c_line);
-
-/*!
- * \brief Allocate an SDP Session
- *
- * \param session_name The session name
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_s_line *ast_sdp_s_alloc(const char *session_name);
-
-/*!
- * \brief Allocate SDP Timing
- *
- * \param start_time (Seconds since 1900)
- * \param end_time (Seconds since 1900)
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_t_line *ast_sdp_t_alloc(uint64_t start_time, uint64_t stop_time);
-
-/*!
- * \brief Allocate an SDP Origin
- *
- * \param username User name
- * \param sesison_id Session ID
- * \param sesison_version Session Version
- * \param address_type Address type ("IN4", "IN6", etc)
- * \param address Unicast address
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_o_line *ast_sdp_o_alloc(const char *username, uint64_t session_id,
- uint64_t session_version, const char *address_type, const char *address);
-
-/*!
- * \brief Add an SDP Attribute to an SDP
- *
- * \param sdp SDP
- * \param a_line Attribute
- *
- * \retval 0 Success
- * \retval non-0 Failure
- *
- * \since 15
- */
-int ast_sdp_add_a(struct ast_sdp *sdp, struct ast_sdp_a_line *a_line);
-
-/*!
- * \brief Get the count of Attributes on an SDP
- *
- * \param sdp SDP
- *
- * \returns Number of Attributes
- *
- * \since 15
- */
-int ast_sdp_get_a_count(const struct ast_sdp *sdp);
-
-/*!
- * \brief Get an Attribute from an SDP
- *
- * \param sdp SDP
- * \param index Attribute index
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_a_line *ast_sdp_get_a(const struct ast_sdp *sdp, int index);
-
-/*!
- * \brief Add a Media Description to an SDP
- *
- * \param sdp SDP
- * \param m_line Media Description
- *
- * \retval 0 Success
- * \retval non-0 Failure
- *
- * \since 15
- */
-int ast_sdp_add_m(struct ast_sdp *sdp, struct ast_sdp_m_line *m_line);
-
-/*!
- * \brief Add an RTP Media Description to an SDP
- *
- * \param sdp SDP
- * \param sdp_state SDP state information
- * \param options SDP Options
- * \param stream_index stream
- *
- * \retval 0 Success
- * \retval non-0 Failure
- *
- * \since 15
- */
-int ast_sdp_add_m_from_rtp_stream(struct ast_sdp *sdp, const struct ast_sdp_state *sdp_state,
- const struct ast_sdp_options *options, int stream_index);
-
-/*!
- * \brief Get the count of Media Descriptions on an SDP
- *
- * \param sdp SDP
- *
- * \returns The number of Media Descriptions
- *
- * \since 15
- */
-int ast_sdp_get_m_count(const struct ast_sdp *sdp);
-
-/*!
- * \brief Get a Media Descriptions from an SDP
- *
- * \param sdp SDP
- * \param index Media Description index
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_m_line *ast_sdp_get_m(const struct ast_sdp *sdp, int index);
-
-/*!
- * \brief Add an SDP Attribute to a Media Description
- *
- * \param m_line Media Description
- * \param a_line Attribute
- *
- * \retval 0 Success
- * \retval non-0 Failure
- *
- * \since 15
- */
-int ast_sdp_m_add_a(struct ast_sdp_m_line *m_line, struct ast_sdp_a_line *a_line);
-
-/*!
- * \brief Get the count of Attributes on a Media Description
- *
- * \param m_line Media Description
- *
- * \returns Number of Attributes
- *
- * \since 15
- */
-int ast_sdp_m_get_a_count(const struct ast_sdp_m_line *m_line);
-
-/*!
- * \brief Get an Attribute from a Media Description
- *
- * \param m_line Media Description
- * \param index Attribute index
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_a_line *ast_sdp_m_get_a(const struct ast_sdp_m_line *m_line, int index);
-
-/*!
- * \brief Add a Payload to a Media Description
- *
- * \param m_line Media Description
- * \param payload Payload
- *
- * \retval 0 Success
- * \retval non-0 Failure
- *
- * \since 15
- */
-int ast_sdp_m_add_payload(struct ast_sdp_m_line *m_line,
- struct ast_sdp_payload *payload);
-
-/*!
- * \brief Get the count of Payloads on a Media Description
- *
- * \param m_line Media Description
- *
- * \returns Number of Attributes
- *
- * \since 15
- */
-int ast_sdp_m_get_payload_count(const struct ast_sdp_m_line *m_line);
-
-/*!
- * \brief Get a Payload from a Media Description
- *
- * \param m_line Media Description
- * \param index Payload index
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp_payload *ast_sdp_m_get_payload(const struct ast_sdp_m_line *m_line, int index);
-
-/*!
- * \brief Add a Format to a Media Description
- *
- * \param m_line Media Description
- * \param options SDP Options
- * \param rtp_code rtp_code from ast_rtp_codecs_payload_code
- * \param asterisk_format True if the value in format is to be used.
- * \param format Format
- * \param code from AST_RTP list
- *
- * \retval 0 Success
- * \retval non-0 Failure
- *
- * \since 15
- */
-int ast_sdp_m_add_format(struct ast_sdp_m_line *m_line, const struct ast_sdp_options *options,
- int rtp_code, int asterisk_format, const struct ast_format *format, int code);
-
-/*!
- * \brief Create an SDP ao2 object
- *
- * \param o_line Origin
- * \param c_line Connection
- * \param s_line Session
- * \param t_line Timing
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \since 15
- */
-struct ast_sdp *ast_sdp_alloc(struct ast_sdp_o_line *o_line,
- struct ast_sdp_c_line *c_line, struct ast_sdp_s_line *s_line,
- struct ast_sdp_t_line *t_line);
-
-/*!
- * \brief Find the first attribute match index in the top-level SDP
- *
- * \note This will not search within streams for the given attribute.
- *
- * \param sdp The SDP in which to search
- * \param attr_name The name of the attribute to search for
- * \param payload Optional payload number to search for. If irrelevant, set to -1
- *
- * \retval index of attribute line on success.
- * \retval -1 on failure or not found.
- *
- * \since 15.0.0
- */
-int ast_sdp_find_a_first(const struct ast_sdp *sdp, const char *attr_name, int payload);
-
-/*!
- * \brief Find the next attribute match index in the top-level SDP
- *
- * \note This will not search within streams for the given attribute.
- *
- * \param sdp The SDP in which to search
- * \param last The last matching index found
- * \param attr_name The name of the attribute to search for
- * \param payload Optional payload number to search for. If irrelevant, set to -1
- *
- * \retval index of attribute line on success.
- * \retval -1 on failure or not found.
- *
- * \since 15.0.0
- */
-int ast_sdp_find_a_next(const struct ast_sdp *sdp, int last, const char *attr_name, int payload);
-
-/*!
- * \brief Find an attribute in the top-level SDP
- *
- * \note This will not search within streams for the given attribute.
- *
- * \param sdp The SDP in which to search
- * \param attr_name The name of the attribute to search for
- * \param payload Optional payload number to search for. If irrelevant, set to -1
- *
- * \retval NULL Could not find the given attribute
- * \retval Non-NULL The attribute to find
- *
- * \since 15.0.0
- */
-struct ast_sdp_a_line *ast_sdp_find_attribute(const struct ast_sdp *sdp,
- const char *attr_name, int payload);
-
-/*!
- * \brief Find the first attribute match index in an SDP stream (m-line)
- *
- * \param m_line The SDP m-line in which to search
- * \param attr_name The name of the attribute to search for
- * \param payload Optional payload number to search for. If irrelevant, set to -1
- *
- * \retval index of attribute line on success.
- * \retval -1 on failure or not found.
- *
- * \since 15.0.0
- */
-int ast_sdp_m_find_a_first(const struct ast_sdp_m_line *m_line, const char *attr_name,
- int payload);
-
-/*!
- * \brief Find the next attribute match index in an SDP stream (m-line)
- *
- * \param m_line The SDP m-line in which to search
- * \param last The last matching index found
- * \param attr_name The name of the attribute to search for
- * \param payload Optional payload number to search for. If irrelevant, set to -1
- *
- * \retval index of attribute line on success.
- * \retval -1 on failure or not found.
- *
- * \since 15.0.0
- */
-int ast_sdp_m_find_a_next(const struct ast_sdp_m_line *m_line, int last,
- const char *attr_name, int payload);
-
-/*!
- * \brief Find an attribute in an SDP stream (m-line)
- *
- * \param m_line The SDP m-line in which to search
- * \param attr_name The name of the attribute to search for
- * \param payload Optional payload number to search for. If irrelevant, set to -1
- *
- * \retval NULL Could not find the given attribute
- * \retval Non-NULL The attribute to find
- *
- * \since 15.0.0
- */
-struct ast_sdp_a_line *ast_sdp_m_find_attribute(const struct ast_sdp_m_line *m_line,
- const char *attr_name, int payload);
-
-/*!
- * \brief Convert an SDP a_line into an rtpmap
- *
- * The returned value is heap-allocated and must be freed with
- * ast_sdp_rtpmap_free()
- *
- * \param a_line The SDP a_line to convert
- *
- * \retval NULL Fail
- * \retval non-NULL Success
- *
- * \since 15.0.0
- */
-struct ast_sdp_rtpmap *ast_sdp_a_get_rtpmap(const struct ast_sdp_a_line *a_line);
-
-
-/*!
- * \brief Allocate a new SDP rtpmap
- *
- * \param payload The RTP payload number
- * \param encoding_name The human-readable name for the codec
- * \param clock_rate The rate of the codec, in cycles per second
- * \param encoding_parameters Optional codec-specific parameters (such as number of channels)
- *
- * \retval NULL Fail
- * \retval non-NULL Success
- *
- * \since 15.0.0
- */
-struct ast_sdp_rtpmap *ast_sdp_rtpmap_alloc(int payload, const char *encoding_name,
- int clock_rate, const char *encoding_parameters);
-
-/*!
- * \brief Free an SDP rtpmap
- *
- * \since 15.0.0
- */
-void ast_sdp_rtpmap_free(struct ast_sdp_rtpmap *rtpmap);
-
-/*!
- * \brief Turn an SDP into a stream topology
- *
- * This traverses the m-lines of the SDP and creates a stream topology, with
- * each m-line corresponding to a stream in the created topology.
- *
- * \param sdp The SDP to convert
- * \param g726_non_standard Non-zero if G.726 is non-standard
- *
- * \retval NULL An error occurred when converting
- * \retval non-NULL The generated stream topology
- *
- * \since 15.0.0
- */
-struct ast_stream_topology *ast_get_topology_from_sdp(const struct ast_sdp *sdp, int g726_non_standard);
-#endif /* _SDP_PRIV_H */
diff --git a/include/asterisk/sdp_options.h b/include/asterisk/sdp_options.h
deleted file mode 100644
index e45ae8cb1..000000000
--- a/include/asterisk/sdp_options.h
+++ /dev/null
@@ -1,774 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#ifndef _ASTERISK_SDP_OPTIONS_H
-#define _ASTERISK_SDP_OPTIONS_H
-
-#include "asterisk/udptl.h"
-#include "asterisk/format_cap.h"
-
-struct ast_sdp_options;
-
-/*!
- * \brief SDP DTMF mode options
- */
-enum ast_sdp_options_dtmf {
- /*! No DTMF to be used */
- AST_SDP_DTMF_NONE,
- /*! Use RFC 4733 events for DTMF */
- AST_SDP_DTMF_RFC_4733,
- /*! Use DTMF in the audio stream */
- AST_SDP_DTMF_INBAND,
- /*! Use SIP 4733 if supported by the other side or INBAND if not */
- AST_SDP_DTMF_AUTO,
-};
-
-/*!
- * \brief ICE options
- *
- * This is an enum because it will support a TRICKLE-ICE option
- * in the future.
- */
-enum ast_sdp_options_ice {
- /*! ICE is not enabled on this session */
- AST_SDP_ICE_DISABLED,
- /*! Standard ICE is enabled on this session */
- AST_SDP_ICE_ENABLED_STANDARD,
-};
-
-/*!
- * \brief Implementation of the SDP
- *
- * Users of the SDP API set the implementation based on what they
- * natively handle. This indicates the type of SDP that the API expects
- * when being given an SDP, and it indicates the type of SDP that the API
- * returns when asked for one.
- */
-enum ast_sdp_options_impl {
- /*! SDP is represented as a string */
- AST_SDP_IMPL_STRING,
- /*! SDP is represented as a pjmedia_sdp_session */
- AST_SDP_IMPL_PJMEDIA,
- /*! End of the list */
- AST_SDP_IMPL_END,
-};
-
-/*!
- * \brief SDP encryption options
- */
-enum ast_sdp_options_encryption {
- /*! No encryption */
- AST_SDP_ENCRYPTION_DISABLED,
- /*! SRTP SDES encryption */
- AST_SDP_ENCRYPTION_SRTP_SDES,
- /*! DTLS encryption */
- AST_SDP_ENCRYPTION_DTLS,
-};
-
-/*!
- * \brief Callback when processing an offer SDP for our answer SDP.
- * \since 15.0.0
- *
- * \details
- * This callback is called after merging our last negotiated topology
- * with the remote's offer topology and before we have sent our answer
- * SDP. At this point you can alter new_topology streams. You can
- * decline, remove formats, or rename streams. Changing anything else
- * on the streams is likely to not end well.
- *
- * * To decline a stream simply set the stream state to
- * AST_STREAM_STATE_REMOVED. You could implement a maximum number
- * of active streams of a given type policy.
- *
- * * To remove formats use the format API to remove any formats from a
- * stream. The streams have the current joint negotiated formats.
- * Most likely you would want to remove all but the first format.
- *
- * * To rename a stream you need to clone the stream and give it a
- * new name and then set it in new_topology using
- * ast_stream_topology_set_stream().
- *
- * \note Removing all formats is an error. You should decline the
- * stream instead.
- *
- * \param context User supplied context data pointer for the SDP
- * state.
- * \param old_topology Active negotiated topology. NULL if this is
- * the first SDP negotiation. The old topology is available so you
- * can tell if any streams are new or changing type.
- * \param new_topology New negotiated topology that we intend to
- * generate the answer SDP.
- *
- * \return Nothing
- */
-typedef void (*ast_sdp_answerer_modify_cb)(void *context,
- const struct ast_stream_topology *old_topology,
- struct ast_stream_topology *new_topology);
-
-/*!
- * \internal
- * \brief Callback when generating a topology for our SDP offer.
- * \since 15.0.0
- *
- * \details
- * This callback is called after merging any topology updates from the
- * system by ast_sdp_state_update_local_topology() and before we have
- * sent our offer SDP. At this point you can alter new_topology
- * streams. You can decline, add/remove/update formats, or rename
- * streams. Changing anything else on the streams is likely to not
- * end well.
- *
- * * To decline a stream simply set the stream state to
- * AST_STREAM_STATE_REMOVED. You could implement a maximum number
- * of active streams of a given type policy.
- *
- * * To update formats use the format API to change formats of the
- * streams. The streams have the current proposed formats. You
- * could do whatever you want for formats but you should stay within
- * the configured formats for the stream type's endpoint. However,
- * you should use ast_sdp_state_update_local_topology() instead of
- * this backdoor method.
- *
- * * To rename a stream you need to clone the stream and give it a
- * new name and then set it in new_topology using
- * ast_stream_topology_set_stream().
- *
- * \note Removing all formats is an error. You should decline the
- * stream instead.
- *
- * \note Declined new streams that are in slots higher than present in
- * old_topology are removed so the SDP can be smaller. The remote has
- * never seen those slots so we shouldn't bother keeping them.
- *
- * \param context User supplied context data pointer for the SDP
- * state.
- * \param old_topology Active negotiated topology. NULL if this is
- * the first SDP negotiation. The old topology is available so you
- * can tell if any streams are new or changing type.
- * \param new_topology Merged topology that we intend to generate the
- * offer SDP.
- *
- * \return Nothing
- */
-typedef void (*ast_sdp_offerer_modify_cb)(void *context,
- const struct ast_stream_topology *old_topology,
- struct ast_stream_topology *new_topology);
-
-/*!
- * \brief Callback when generating an offer SDP to configure extra stream data.
- * \since 15.0.0
- *
- * \details
- * This callback is called after any ast_sdp_offerer_modify_cb
- * callback and before we have sent our offer SDP. The callback can
- * call several SDP API calls to configure the proposed capabilities
- * of streams before we create the SDP offer. For example, the
- * callback could configure a stream specific connection address, T.38
- * parameters, RTP instance, or UDPTL instance parameters.
- *
- * \param context User supplied context data pointer for the SDP
- * state.
- * \param topology Topology ready to configure extra stream options.
- *
- * \return Nothing
- */
-typedef void (*ast_sdp_offerer_config_cb)(void *context, const struct ast_stream_topology *topology);
-
-/*!
- * \brief Callback before applying a topology.
- * \since 15.0.0
- *
- * \details
- * This callback is called before the topology is applied so the
- * using module can do what is necessary before the topology becomes
- * active.
- *
- * \param context User supplied context data pointer for the SDP
- * state.
- * \param topology Topology ready to be applied.
- *
- * \return Nothing
- */
-typedef void (*ast_sdp_preapply_cb)(void *context, const struct ast_stream_topology *topology);
-
-/*!
- * \brief Callback after applying a topology.
- * \since 15.0.0
- *
- * \details
- * This callback is called after the topology is applied so the
- * using module can do what is necessary after the topology becomes
- * active.
- *
- * \param context User supplied context data pointer for the SDP
- * state.
- * \param topology Topology already applied.
- *
- * \return Nothing
- */
-typedef void (*ast_sdp_postapply_cb)(void *context, const struct ast_stream_topology *topology);
-
-/*!
- * \since 15.0.0
- * \brief Allocate a new SDP options structure.
- *
- * This will heap-allocate an SDP options structure and
- * initialize it to a set of default values.
- *
- * \retval NULL Allocation failure
- * \retval non-NULL Newly allocated SDP options
- */
-struct ast_sdp_options *ast_sdp_options_alloc(void);
-
-/*!
- * \since 15.0.0
- * \brief Free an SDP options structure.
- *
- * \note This only needs to be called if an error occurs between
- * options allocation and a call to ast_sdp_state_alloc()
- * Otherwise, the SDP state will take care of freeing the
- * options for you.
- *
- * \param options The options to free
- */
-void ast_sdp_options_free(struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options media_address
- *
- * \param options SDP Options
- * \param media_address
- */
-void ast_sdp_options_set_media_address(struct ast_sdp_options *options,
- const char *media_address);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options media_address
- *
- * \param options SDP Options
- *
- * \returns media_address
- */
-const char *ast_sdp_options_get_media_address(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options interface_address
- *
- * \param options SDP Options
- * \param interface_address
- */
-void ast_sdp_options_set_interface_address(struct ast_sdp_options *options,
- const char *interface_address);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options interface_address
- *
- * \param options SDP Options
- *
- * \returns interface_address
- */
-const char *ast_sdp_options_get_interface_address(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options sdpowner
- *
- * \param options SDP Options
- * \param sdpowner
- */
-void ast_sdp_options_set_sdpowner(struct ast_sdp_options *options,
- const char *sdpowner);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options sdpowner
- *
- * \param options SDP Options
- *
- * \returns sdpowner
- */
-const char *ast_sdp_options_get_sdpowner(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options sdpsession
- *
- * \param options SDP Options
- * \param sdpsession
- */
-void ast_sdp_options_set_sdpsession(struct ast_sdp_options *options,
- const char *sdpsession);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options sdpsession
- *
- * \param options SDP Options
- *
- * \returns sdpsession
- */
-const char *ast_sdp_options_get_sdpsession(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options rtp_engine
- *
- * \param options SDP Options
- * \param rtp_engine
- */
-void ast_sdp_options_set_rtp_engine(struct ast_sdp_options *options,
- const char *rtp_engine);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options rtp_engine
- *
- * \param options SDP Options
- *
- * \returns rtp_engine
- */
-const char *ast_sdp_options_get_rtp_engine(const struct ast_sdp_options *options);
-
-void ast_sdp_options_set_state_context(struct ast_sdp_options *options, void *state_context);
-void *ast_sdp_options_get_state_context(const struct ast_sdp_options *options);
-
-void ast_sdp_options_set_answerer_modify_cb(struct ast_sdp_options *options, ast_sdp_answerer_modify_cb answerer_modify_cb);
-ast_sdp_answerer_modify_cb ast_sdp_options_get_answerer_modify_cb(const struct ast_sdp_options *options);
-
-void ast_sdp_options_set_offerer_modify_cb(struct ast_sdp_options *options, ast_sdp_offerer_modify_cb offerer_modify_cb);
-ast_sdp_offerer_modify_cb ast_sdp_options_get_offerer_modify_cb(const struct ast_sdp_options *options);
-
-void ast_sdp_options_set_offerer_config_cb(struct ast_sdp_options *options, ast_sdp_offerer_config_cb offerer_config_cb);
-ast_sdp_offerer_config_cb ast_sdp_options_get_offerer_config_cb(const struct ast_sdp_options *options);
-
-void ast_sdp_options_set_preapply_cb(struct ast_sdp_options *options, ast_sdp_preapply_cb preapply_cb);
-ast_sdp_preapply_cb ast_sdp_options_get_preapply_cb(const struct ast_sdp_options *options);
-
-void ast_sdp_options_set_postapply_cb(struct ast_sdp_options *options, ast_sdp_postapply_cb postapply_cb);
-ast_sdp_postapply_cb ast_sdp_options_get_postapply_cb(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options rtp_symmetric
- *
- * \param options SDP Options
- * \param rtp_symmetric
- */
-void ast_sdp_options_set_rtp_symmetric(struct ast_sdp_options *options,
- unsigned int rtp_symmetric);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options rtp_symmetric
- *
- * \param options SDP Options
- *
- * \returns rtp_symmetric
- */
-unsigned int ast_sdp_options_get_rtp_symmetric(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options rtp_ipv6
- *
- * \param options SDP Options
- * \param rtp_ipv6
- */
-void ast_sdp_options_set_rtp_ipv6(struct ast_sdp_options *options,
- unsigned int rtp_ipv6);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options rtp_ipv6
- *
- * \param options SDP Options
- *
- * \returns rtp_ipv6
- */
-unsigned int ast_sdp_options_get_rtp_ipv6(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options g726_non_standard
- *
- * \param options SDP Options
- * \param g726_non_standard
- */
-void ast_sdp_options_set_g726_non_standard(struct ast_sdp_options *options,
- unsigned int g726_non_standard);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options g726_non_standard
- *
- * \param options SDP Options
- *
- * \returns g726_non_standard
- */
-unsigned int ast_sdp_options_get_g726_non_standard(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options tos_audio
- *
- * \param options SDP Options
- * \param tos_audio
- */
-void ast_sdp_options_set_tos_audio(struct ast_sdp_options *options,
- unsigned int tos_audio);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options tos_audio
- *
- * \param options SDP Options
- *
- * \returns tos_audio
- */
-unsigned int ast_sdp_options_get_tos_audio(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options cos_audio
- *
- * \param options SDP Options
- * \param cos_audio
- */
-void ast_sdp_options_set_cos_audio(struct ast_sdp_options *options,
- unsigned int cos_audio);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options cos_audio
- *
- * \param options SDP Options
- *
- * \returns cos_audio
- */
-unsigned int ast_sdp_options_get_cos_audio(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options tos_video
- *
- * \param options SDP Options
- * \param tos_video
- */
-void ast_sdp_options_set_tos_video(struct ast_sdp_options *options,
- unsigned int tos_video);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options tos_video
- *
- * \param options SDP Options
- *
- * \returns tos_video
- */
-unsigned int ast_sdp_options_get_tos_video(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options cos_video
- *
- * \param options SDP Options
- * \param cos_video
- */
-void ast_sdp_options_set_cos_video(struct ast_sdp_options *options,
- unsigned int cos_video);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options cos_video
- *
- * \param options SDP Options
- *
- * \returns cos_video
- */
-unsigned int ast_sdp_options_get_cos_video(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options dtmf
- *
- * \param options SDP Options
- * \param dtmf
- */
-void ast_sdp_options_set_dtmf(struct ast_sdp_options *options,
- enum ast_sdp_options_dtmf dtmf);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options dtmf
- *
- * \param options SDP Options
- *
- * \returns dtmf
- */
-enum ast_sdp_options_dtmf ast_sdp_options_get_dtmf(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options ice
- *
- * \param options SDP Options
- * \param ice
- */
-void ast_sdp_options_set_ice(struct ast_sdp_options *options,
- enum ast_sdp_options_ice ice);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options ice
- *
- * \param options SDP Options
- *
- * \returns ice
- */
-enum ast_sdp_options_ice ast_sdp_options_get_ice(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options impl
- *
- * \param options SDP Options
- * \param impl
- */
-void ast_sdp_options_set_impl(struct ast_sdp_options *options,
- enum ast_sdp_options_impl impl);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options impl
- *
- * \param options SDP Options
- *
- * \returns impl
- */
-enum ast_sdp_options_impl ast_sdp_options_get_impl(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options encryption
- *
- * \param options SDP Options
- * \param encryption
- */
-void ast_sdp_options_set_encryption(struct ast_sdp_options *options,
- enum ast_sdp_options_encryption encryption);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options encryption
- *
- * \param options SDP Options
- *
- * \returns encryption
- */
-enum ast_sdp_options_encryption ast_sdp_options_get_encryption(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options RTCP MUX
- *
- * \param options SDP Options
- *
- * \returns Boolean indicating if RTCP MUX is enabled.
- */
-unsigned int ast_sdp_options_get_rtcp_mux(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options RTCP MUX
- *
- * \param options SDP Options
- * \param value Boolean that indicates if RTCP MUX should be enabled.
- */
-void ast_sdp_options_set_rtcp_mux(struct ast_sdp_options *options, unsigned int value);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options udptl_symmetric
- *
- * \param options SDP Options
- * \param udptl_symmetric
- */
-void ast_sdp_options_set_udptl_symmetric(struct ast_sdp_options *options,
- unsigned int udptl_symmetric);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options udptl_symmetric
- *
- * \param options SDP Options
- *
- * \returns udptl_symmetric
- */
-unsigned int ast_sdp_options_get_udptl_symmetric(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options udptl_error_correction
- *
- * \param options SDP Options
- * \param error_correction
- */
-void ast_sdp_options_set_udptl_error_correction(struct ast_sdp_options *options,
- enum ast_t38_ec_modes error_correction);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options udptl_error_correction
- *
- * \param options SDP Options
- *
- * \returns udptl_error_correction
- */
-enum ast_t38_ec_modes ast_sdp_options_get_udptl_error_correction(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options udptl_far_max_datagram
- *
- * \param options SDP Options
- * \param far_max_datagram
- */
-void ast_sdp_options_set_udptl_far_max_datagram(struct ast_sdp_options *options,
- unsigned int far_max_datagram);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options udptl_far_max_datagram
- *
- * \param options SDP Options
- *
- * \returns udptl_far_max_datagram
- */
-unsigned int ast_sdp_options_get_udptl_far_max_datagram(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Set SDP Options max_streams
- *
- * \param options SDP Options
- * \param max_streams
- */
-void ast_sdp_options_set_max_streams(struct ast_sdp_options *options,
- unsigned int max_streams);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options max_streams
- *
- * \param options SDP Options
- *
- * \returns max_streams
- */
-unsigned int ast_sdp_options_get_max_streams(const struct ast_sdp_options *options);
-
-/*!
- * \since 15.0.0
- * \brief Enable setting SSRC level attributes on SDPs
- *
- * \param options SDP Options
- * \param ssrc Boolean indicating if SSRC attributes should be included in generated SDPs
- */
-void ast_sdp_options_set_ssrc(struct ast_sdp_options *options, unsigned int ssrc);
-
-/*!
- * \since 15.0.0
- * \brief Get SDP Options ssrc
- *
- * \param options SDP Options
- *
- * \returns Whether SSRC-level attributes will be added to our SDP.
- */
-unsigned int ast_sdp_options_get_ssrc(const struct ast_sdp_options *options);
-
-/*!
- * \brief Set the SDP options scheduler context used to create new streams of the type.
- * \since 15.0.0
- *
- * \param options SDP Options
- * \param type Media type the scheduler context is for.
- * \param sched Scheduler context to use for the specified media type.
- *
- * \return Nothing
- */
-void ast_sdp_options_set_sched_type(struct ast_sdp_options *options,
- enum ast_media_type type, struct ast_sched_context *sched);
-
-/*!
- * \brief Get the SDP options scheduler context used to create new streams of the type.
- * \since 15.0.0
- *
- * \param options SDP Options
- * \param type Media type the format cap represents.
- *
- * \return The stored scheduler context to create new streams of the type.
- */
-struct ast_sched_context *ast_sdp_options_get_sched_type(const struct ast_sdp_options *options,
- enum ast_media_type type);
-
-/*!
- * \brief Set all allowed stream types to create new streams.
- * \since 15.0.0
- *
- * \param options SDP Options
- * \param cap Format capabilities to set all allowed stream types at once.
- * Could be NULL to disable creating any new streams.
- *
- * \return Nothing
- */
-void ast_sdp_options_set_format_caps(struct ast_sdp_options *options,
- struct ast_format_cap *cap);
-
-/*!
- * \brief Set the SDP options format cap used to create new streams of the type.
- * \since 15.0.0
- *
- * \param options SDP Options
- * \param type Media type the format cap represents.
- * \param cap Format capabilities to use for the specified media type.
- * Could be NULL to disable creating new streams of type.
- *
- * \return Nothing
- */
-void ast_sdp_options_set_format_cap_type(struct ast_sdp_options *options,
- enum ast_media_type type, struct ast_format_cap *cap);
-
-/*!
- * \brief Get the SDP options format cap used to create new streams of the type.
- * \since 15.0.0
- *
- * \param options SDP Options
- * \param type Media type the format cap represents.
- *
- * \retval NULL if stream not allowed to be created.
- * \retval cap to use in negotiating the new stream.
- *
- * \note The returned cap does not have its own ao2 ref.
- */
-struct ast_format_cap *ast_sdp_options_get_format_cap_type(const struct ast_sdp_options *options,
- enum ast_media_type type);
-
-#endif /* _ASTERISK_SDP_OPTIONS_H */
diff --git a/include/asterisk/sdp_state.h b/include/asterisk/sdp_state.h
deleted file mode 100644
index ec9d502e2..000000000
--- a/include/asterisk/sdp_state.h
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#ifndef _ASTERISK_SDP_STATE_H
-#define _ASTERISK_SDP_STATE_H
-
-#include "asterisk/stream.h"
-#include "asterisk/sdp_options.h"
-
-struct ast_sdp_state;
-struct ast_sockaddr;
-struct ast_udptl;
-struct ast_control_t38_parameters;
-
-/*!
- * \brief Allocate a new SDP state
- *
- * \details
- * SDP state keeps tabs on everything SDP-related for a media session.
- * Most SDP operations will require the state to be provided.
- * Ownership of the SDP options is taken on by the SDP state.
- * A good strategy is to call this during session creation.
- *
- * \param topology Initial stream topology to offer.
- * NULL if we are going to be the answerer. We can always
- * update the local topology later if it turns out we need
- * to be the offerer.
- * \param options SDP options for the duration of the session.
- *
- * \retval SDP state struct
- * \retval NULL on failure
- */
-struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *topology,
- struct ast_sdp_options *options);
-
-/*!
- * \brief Free the SDP state.
- *
- * A good strategy is to call this during session destruction
- */
-void ast_sdp_state_free(struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Get the associated RTP instance for a particular stream on the SDP state.
- *
- * Stream numbers correspond to the streams in the topology of the associated channel
- */
-struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(const struct ast_sdp_state *sdp_state,
- int stream_index);
-
-/*!
- * \brief Get the associated UDPTL instance for a particular stream on the SDP state.
- *
- * Stream numbers correspond to the streams in the topology of the associated channel
- */
-struct ast_udptl *ast_sdp_state_get_udptl_instance(const struct ast_sdp_state *sdp_state,
- int stream_index);
-
-/*!
- * \brief Get the global connection address on the SDP state.
- */
-const struct ast_sockaddr *ast_sdp_state_get_connection_address(const struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Get the connection address for a particular stream.
- *
- * \param sdp_state
- * \param stream_index The particular stream to get the connection address of
- * \param address[out] A place to store the address in
- *
- * \retval 0 Success
- *
- * \note
- * Stream numbers correspond to the streams in the topology of the associated channel
- */
-int ast_sdp_state_get_stream_connection_address(const struct ast_sdp_state *sdp_state,
- int stream_index, struct ast_sockaddr *address);
-
-/*!
- * \brief Get the joint negotiated streams based on local and remote capabilities.
- *
- * If this is called prior to receiving a remote SDP, then this will just mirror
- * the local configured endpoint capabilities.
- *
- * \note Cannot return NULL. It is a BUG if it does.
- */
-const struct ast_stream_topology *ast_sdp_state_get_joint_topology(
- const struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Get the local topology
- *
- * \note Cannot return NULL. It is a BUG if it does.
- */
-const struct ast_stream_topology *ast_sdp_state_get_local_topology(
- const struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Get the sdp_state options
- *
- */
-const struct ast_sdp_options *ast_sdp_state_get_options(
- const struct ast_sdp_state *sdp_state);
-
-
-/*!
- * \brief Get the local SDP.
- *
- * \param sdp_state
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \note
- * This function will return the last local SDP created if one were
- * previously requested for the current negotiation. Otherwise it
- * creates our SDP offer/answer depending on what role we are playing
- * in the current negotiation.
- */
-const struct ast_sdp *ast_sdp_state_get_local_sdp(struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Get the local SDP Implementation.
- *
- * \param sdp_state
- *
- * \retval non-NULL Success
- * \retval NULL Failure
- *
- * \note
- * This function calls ast_sdp_state_get_local_sdp then translates it into
- * the defined implementation.
- *
- * The return here is const. The use case for this is so that a channel can add
- * the SDP to an outgoing message. The API user should not attempt to modify the SDP.
- * SDP modification should only be done through the API.
- *
- * \since 15
- */
-const void *ast_sdp_state_get_local_sdp_impl(struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Set the remote SDP
- *
- * \param sdp_state
- * \param sdp
- *
- * \note It is assumed that the passed in SDP has been checked for sanity
- * already. e.g., There are no syntax errors, a c= line is reachable for
- * each m= line, etc...
- *
- * \retval 0 Success
- * \retval non-0 Failure
- * Use ast_sdp_state_is_offer_rejected() to see if the SDP offer was rejected.
- *
- * \since 15
- */
-int ast_sdp_state_set_remote_sdp(struct ast_sdp_state *sdp_state, const struct ast_sdp *sdp);
-
-/*!
- * \brief Set the remote SDP from an Implementation
- *
- * \param sdp_state
- * \param remote The implementation's representation of an SDP.
- *
- * \retval 0 Success
- * \retval non-0 Failure
- * Use ast_sdp_state_is_offer_rejected() to see if the SDP offer was rejected.
- *
- * \since 15
- */
-int ast_sdp_state_set_remote_sdp_from_impl(struct ast_sdp_state *sdp_state, const void *remote);
-
-/*!
- * \brief Was the set remote offer rejected.
- * \since 15.0.0
- *
- * \param sdp_state
- *
- * \retval 0 if not rejected.
- * \retval non-zero if rejected.
- */
-int ast_sdp_state_is_offer_rejected(struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Are we the SDP offerer.
- * \since 15.0.0
- *
- * \param sdp_state
- *
- * \retval 0 if we are not the offerer.
- * \retval non-zero we are the offerer.
- */
-int ast_sdp_state_is_offerer(struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Are we the SDP answerer.
- * \since 15.0.0
- *
- * \param sdp_state
- *
- * \retval 0 if we are not the answerer.
- * \retval non-zero we are the answerer.
- */
-int ast_sdp_state_is_answerer(struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Restart the SDP offer/answer negotiations.
- *
- * \param sdp_state
- *
- * \retval 0 Success
- * \retval non-0 Failure
- */
-int ast_sdp_state_restart_negotiations(struct ast_sdp_state *sdp_state);
-
-/*!
- * \brief Update the local stream topology on the SDP state.
- *
- * \details
- * Basically we are saving off any topology updates until we create the
- * next SDP offer. Repeated updates merge with the previous updated
- * topology.
- *
- * \param sdp_state
- * \param topology The new stream topology.
- *
- * \retval 0 Success
- * \retval non-0 Failure
- *
- * \since 15
- */
-int ast_sdp_state_update_local_topology(struct ast_sdp_state *sdp_state, struct ast_stream_topology *topology);
-
-/*!
- * \brief Set the local address (IP address) to use for connection addresses
- *
- * \param sdp_state
- * \param address The local address
- *
- * \note
- * Passing NULL as an address will unset the explicit local connection address.
- *
- * \since 15
- */
-void ast_sdp_state_set_local_address(struct ast_sdp_state *sdp_state, struct ast_sockaddr *address);
-
-/*!
- * \brief Set the connection address (IP address and port) to use for a specific stream
- *
- * \param sdp_state
- * \param stream_index The stream to set the connection address for
- * \param address The connection address
- *
- * \retval 0 Success
- *
- * \note
- * Passing NULL as an address will unset the explicit local connection address.
- *
- * \since 15
- */
-int ast_sdp_state_set_connection_address(struct ast_sdp_state *sdp_state, int stream_index,
- struct ast_sockaddr *address);
-
-/*!
- * \since 15.0.0
- * \brief Set the global locally held state.
- *
- * \param sdp_state
- * \param locally_held
- */
-void ast_sdp_state_set_global_locally_held(struct ast_sdp_state *sdp_state, unsigned int locally_held);
-
-/*!
- * \since 15.0.0
- * \brief Get the global locally held state.
- *
- * \param sdp_state
- *
- * \returns locally_held
- */
-unsigned int ast_sdp_state_get_global_locally_held(const struct ast_sdp_state *sdp_state);
-
-/*!
- * \since 15.0.0
- * \brief Set a stream to be held or unheld locally
- *
- * \param sdp_state
- * \param stream_index The stream to set the held value for
- * \param locally_held
- */
-void ast_sdp_state_set_locally_held(struct ast_sdp_state *sdp_state,
- int stream_index, unsigned int locally_held);
-
-/*!
- * \since 15.0.0
- * \brief Get whether a stream is locally held or not
- *
- * \param sdp_state
- * \param stream_index The stream to get the held state for
- *
- * \returns locally_held
- */
-unsigned int ast_sdp_state_get_locally_held(const struct ast_sdp_state *sdp_state,
- int stream_index);
-
-/*!
- * \since 15.0.0
- * \brief Get whether a stream is remotely held or not
- *
- * \param sdp_state
- * \param stream_index The stream to get the held state for
- *
- * \returns remotely_held
- */
-unsigned int ast_sdp_state_get_remotely_held(const struct ast_sdp_state *sdp_state,
- int stream_index);
-
-/*!
- * \since 15.0.0
- * \brief Set the UDPTL session parameters
- *
- * \param sdp_state
- * \param stream_index The stream to set the UDPTL session parameters for
- * \param params
- */
-void ast_sdp_state_set_t38_parameters(struct ast_sdp_state *sdp_state,
- int stream_index, struct ast_control_t38_parameters *params);
-
-#endif /* _ASTERISK_SDP_STATE_H */
diff --git a/include/asterisk/sdp_translator.h b/include/asterisk/sdp_translator.h
deleted file mode 100644
index e1d51f0be..000000000
--- a/include/asterisk/sdp_translator.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#ifndef _ASTERISK_SDP_TRANSLATOR_H
-#define _ASTERISK_SDP_TRANSLATOR_H
-
-#include "asterisk/sdp_options.h"
-
-struct sdp;
-
-/*!
- * \brief SDP translator operations
- */
-struct ast_sdp_translator_ops {
- /*! The SDP representation on which this translator operates */
- enum ast_sdp_options_impl repr;
- /*! Allocate new translator private data for a translator */
- void *(*translator_new)(void);
- /*! Free translator private data */
- void (*translator_free)(void *translator_priv);
- /*! Convert the channel-native SDP into an internal Asterisk SDP */
- struct ast_sdp *(*to_sdp)(const void *repr_sdp, void *translator_priv);
- /*! Convert an internal Asterisk SDP into a channel-native SDP */
- const void *(*from_sdp)(const struct ast_sdp *sdp, void *translator_priv);
-};
-
-/*!
- * \brief An SDP translator
- *
- * An SDP translator is responsible for converting between Asterisk's internal
- * representation of an SDP and the representation that is native to the channel
- * driver. Translators are allocated per-use.
- */
-struct ast_sdp_translator {
- /*! The operations this translator uses */
- struct ast_sdp_translator_ops *ops;
- /*! Private data this translator uses */
- void *translator_priv;
-};
-
-/*!
- * \brief Register an SDP translator
- * \param ops The SDP operations defined by this translator
- * \retval 0 Success
- * \retval -1 FAIL
- */
-int ast_sdp_register_translator(struct ast_sdp_translator_ops *ops);
-
-/*!
- * \brief Unregister an SDP translator
- */
-void ast_sdp_unregister_translator(struct ast_sdp_translator_ops *ops);
-
-/*!
- * \brief Allocate a new SDP translator
- * \param Representation corresponding to the translator_ops to use
- * \retval NULL FAIL
- * \retval non-NULL New SDP translator
- */
-struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_impl repr);
-
-/*!
- * \brief Free an SDP translator
- */
-void ast_sdp_translator_free(struct ast_sdp_translator *translator);
-
-/*!
- * \brief Translate a native SDP to internal Asterisk SDP
- *
- * \param translator The translator to use when translating
- * \param native_sdp The SDP from the channel driver
- * \retval NULL FAIL
- * \retval Non-NULL The translated SDP
- */
-struct ast_sdp *ast_sdp_translator_to_sdp(struct ast_sdp_translator *translator, const void *native_sdp);
-
-/*!
- * \brief Translate an internal Asterisk SDP to a native SDP
- *
- * \param translator The translator to use when translating
- * \param ast_sdp The Asterisk SDP to translate
- * \retval NULL FAIL
- * \retval non-NULL The translated SDP
- */
-const void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator,
- const struct ast_sdp *ast_sdp);
-
-#endif /* _ASTERISK_SDP_TRANSLATOR_H */
diff --git a/include/asterisk/stasis_bridges.h b/include/asterisk/stasis_bridges.h
index 05d356cc2..a455a5b02 100644
--- a/include/asterisk/stasis_bridges.h
+++ b/include/asterisk/stasis_bridges.h
@@ -46,6 +46,8 @@ struct ast_bridge_snapshot {
AST_STRING_FIELD(creator);
/*! Name given to the bridge by its creator */
AST_STRING_FIELD(name);
+ /*! Unique ID of the channel providing video, if one exists */
+ AST_STRING_FIELD(video_source_id);
);
/*! AO2 container of bare channel uniqueid strings participating in the bridge.
* Allocated from ast_str_container_alloc() */
@@ -60,8 +62,6 @@ struct ast_bridge_snapshot {
unsigned int num_active;
/*! The video mode of the bridge */
enum ast_bridge_video_mode_type video_mode;
- /*! Unique ID of the channel providing video, if one exists */
- AST_STRING_FIELD_EXTENDED(video_source_id);
};
/*!
diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h
index c2d5a8877..0a5550b5e 100644
--- a/include/asterisk/stream.h
+++ b/include/asterisk/stream.h
@@ -78,20 +78,6 @@ enum ast_stream_state {
};
/*!
- * \brief Stream data slots
- */
-enum ast_stream_data_slot {
- /*!
- * \brief Data slot for RTP instance
- */
- AST_STREAM_DATA_RTP_CODECS = 0,
- /*!
- * \brief Controls the size of the data pointer array
- */
- AST_STREAM_DATA_SLOT_MAX
-};
-
-/*!
* \brief Create a new media stream representation
*
* \param name A name for the stream
@@ -239,32 +225,47 @@ const char *ast_stream_state2str(enum ast_stream_state state);
enum ast_stream_state ast_stream_str2state(const char *str);
/*!
- * \brief Get the opaque stream data
+ * \brief Get a stream metadata value
*
* \param stream The media stream
- * \param slot The data slot to retrieve
+ * \param m_key An arbitrary metadata key
*
- * \retval non-NULL success
- * \retval NULL failure
+ * \retval non-NULL metadata value
+ * \retval NULL failure or not found
*
- * \since 15
+ * \since 15.5
*/
-void *ast_stream_get_data(struct ast_stream *stream, enum ast_stream_data_slot slot);
+const char *ast_stream_get_metadata(const struct ast_stream *stream,
+ const char *m_key);
/*!
- * \brief Set the opaque stream data
+ * \brief Get all stream metadata keys
*
* \param stream The media stream
- * \param slot The data slot to set
- * \param data Opaque data
- * \param data_free_fn Callback to free data when stream is freed. May be NULL for no action.
*
- * \return data
+ * \retval An ast_variable list of the metadata key/value pairs.
+ * \retval NULL if error or no variables are set.
*
- * \since 15
+ * When you're finished with the list, you must call
+ * ast_variables_destroy(list);
+ *
+ * \since 15.5
+ */
+struct ast_variable *ast_stream_get_metadata_list(const struct ast_stream *stream);
+
+/*!
+ * \brief Set a stream metadata value
+ *
+ * \param stream The media stream
+ * \param m_key An arbitrary metadata key
+ * \param value String metadata value or NULL to remove existing value
+ *
+ * \retval -1 failure
+ * \retval 0 success
+ *
+ * \since 15.5
*/
-void *ast_stream_set_data(struct ast_stream *stream, enum ast_stream_data_slot slot,
- void *data, ast_stream_data_free_fn data_free_fn);
+int ast_stream_set_metadata(struct ast_stream *stream, const char *m_key, const char *value);
/*!
* \brief Get the position of the stream in the topology
@@ -278,6 +279,27 @@ void *ast_stream_set_data(struct ast_stream *stream, enum ast_stream_data_slot s
int ast_stream_get_position(const struct ast_stream *stream);
/*!
+ * \brief Get rtp_codecs associated with the stream
+ *
+ * \param stream The media stream
+ *
+ * \return The rtp_codecs
+ *
+ * \since 15.5
+ */
+struct ast_rtp_codecs *ast_stream_get_rtp_codecs(const struct ast_stream *stream);
+
+/*!
+ * \brief Set rtp_codecs associated with the stream
+ *
+ * \param stream The media stream
+ * \param rtp_codecs The rtp_codecs
+ *
+ * \since 15.5
+ */
+void ast_stream_set_rtp_codecs(struct ast_stream *stream, struct ast_rtp_codecs *rtp_codecs);
+
+/*!
* \brief Create a stream topology
*
* \retval non-NULL success
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 4da7fa465..b892cda9e 100644
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -578,6 +578,13 @@ void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_
#ifdef AST_DEVMODE
#define ast_assert(a) _ast_assert(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+#define ast_assert_return(a, ...) \
+({ \
+ if (__builtin_expect(!(a), 1)) { \
+ _ast_assert(0, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
+ return __VA_ARGS__; \
+ }\
+})
static void force_inline _ast_assert(int condition, const char *condition_str, const char *file, int line, const char *function)
{
if (__builtin_expect(!condition, 1)) {
@@ -586,6 +593,12 @@ static void force_inline _ast_assert(int condition, const char *condition_str, c
}
#else
#define ast_assert(a)
+#define ast_assert_return(a, ...) \
+({ \
+ if (__builtin_expect(!(a), 1)) { \
+ return __VA_ARGS__; \
+ }\
+})
#endif
/*!
diff --git a/main/Makefile b/main/Makefile
index bef70e966..393ad1aa4 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -135,7 +135,8 @@ endif
$(ECHO_PREFIX) echo " [FLEX] $< -> $@"
$(CMD_PREFIX) $(FLEX) -o $@ ast_expr2.fl
$(CMD_PREFIX) sed 's@#if __STDC_VERSION__ >= 199901L@#if !defined __STDC_VERSION__ || __STDC_VERSION__ >= 199901L@' $@ > $@.fix
- $(CMD_PREFIX) echo "#include \"asterisk.h\"" > $@
+ $(CMD_PREFIX) echo "#define ASTMM_LIBC ASTMM_REDIRECT" > $@
+ $(CMD_PREFIX) echo "#include \"asterisk.h\"" >> $@
$(CMD_PREFIX) echo >> $@
$(CMD_PREFIX) cat $@.fix >> $@
$(CMD_PREFIX) rm $@.fix
diff --git a/main/bridge.c b/main/bridge.c
index 93c53dd15..2b347fd3f 100644
--- a/main/bridge.c
+++ b/main/bridge.c
@@ -3852,8 +3852,19 @@ void ast_bridge_set_video_update_discard(struct ast_bridge *bridge, unsigned int
void ast_bridge_set_remb_send_interval(struct ast_bridge *bridge, unsigned int remb_send_interval)
{
+ ast_assert(bridge->softmix.video_mode.mode == AST_BRIDGE_VIDEO_MODE_SFU);
+
+ ast_bridge_lock(bridge);
+ bridge->softmix.video_mode.mode_data.sfu_data.remb_send_interval = remb_send_interval;
+ ast_bridge_unlock(bridge);
+}
+
+void ast_brige_set_remb_behavior(struct ast_bridge *bridge, enum ast_bridge_video_sfu_remb_behavior behavior)
+{
+ ast_assert(bridge->softmix.video_mode.mode == AST_BRIDGE_VIDEO_MODE_SFU);
+
ast_bridge_lock(bridge);
- bridge->softmix.video_mode.remb_send_interval = remb_send_interval;
+ bridge->softmix.video_mode.mode_data.sfu_data.remb_behavior = behavior;
ast_bridge_unlock(bridge);
}
@@ -4427,7 +4438,7 @@ static void set_transfer_variables_all(struct ast_channel *transferer, struct ao
ao2_iterator_destroy(&iter);
}
-static struct ast_bridge *acquire_bridge(struct ast_channel *chan)
+struct ast_bridge *ast_bridge_transfer_acquire_bridge(struct ast_channel *chan)
{
struct ast_bridge *bridge;
@@ -4468,7 +4479,7 @@ enum ast_transfer_result ast_bridge_transfer_blind(int is_external,
return AST_BRIDGE_TRANSFER_FAIL;
}
- bridge = acquire_bridge(transferer);
+ bridge = ast_bridge_transfer_acquire_bridge(transferer);
if (!bridge) {
transfer_result = AST_BRIDGE_TRANSFER_INVALID;
goto publish;
@@ -4715,8 +4726,8 @@ enum ast_transfer_result ast_bridge_transfer_attended(struct ast_channel *to_tra
const char *app = NULL;
int hangup_target = 0;
- to_transferee_bridge = acquire_bridge(to_transferee);
- to_target_bridge = acquire_bridge(to_transfer_target);
+ to_transferee_bridge = ast_bridge_transfer_acquire_bridge(to_transferee);
+ to_target_bridge = ast_bridge_transfer_acquire_bridge(to_transfer_target);
transfer_msg = ast_attended_transfer_message_create(1, to_transferee, to_transferee_bridge,
to_transfer_target, to_target_bridge, NULL, NULL);
diff --git a/main/cli.c b/main/cli.c
index 5730be17b..cf51d0d95 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -1614,19 +1614,29 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
ast_str_append(&output, 0, " -- Streams --\n");
for (stream_num = 0; stream_num < ast_stream_topology_get_count(ast_channel_get_stream_topology(chan)); stream_num++) {
struct ast_stream *stream = ast_stream_topology_get_stream(ast_channel_get_stream_topology(chan), stream_num);
+ struct ast_variable *metadata = ast_stream_get_metadata_list(stream);
ast_str_append(&output, 0,
"Name: %s\n"
" Type: %s\n"
" State: %s\n"
" Group: %d\n"
- " Formats: %s\n",
+ " Formats: %s\n"
+ " Metadata:\n",
ast_stream_get_name(stream),
ast_codec_media_type2str(ast_stream_get_type(stream)),
ast_stream_state2str(ast_stream_get_state(stream)),
ast_stream_get_group(stream),
ast_format_cap_get_names(ast_stream_get_formats(stream), &codec_buf)
);
+
+ if (metadata) {
+ struct ast_variable *v;
+ for(v = metadata; v; v = v->next) {
+ ast_str_append(&output, 0, " %s: %s\n", v->name, v->value);
+ }
+ ast_variables_destroy(metadata);
+ }
}
ast_channel_unlock(chan);
diff --git a/main/sdp.c b/main/sdp.c
deleted file mode 100644
index 7e283ebf8..000000000
--- a/main/sdp.c
+++ /dev/null
@@ -1,951 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * George Joseph <gjoseph@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-
-#include "asterisk.h"
-#include "asterisk/utils.h"
-#include "asterisk/netsock2.h"
-#include "asterisk/codec.h"
-#include "asterisk/format.h"
-#include "asterisk/format_cap.h"
-#include "asterisk/format_cache.h"
-#include "asterisk/rtp_engine.h"
-#include "asterisk/sdp_state.h"
-#include "asterisk/sdp_options.h"
-#include "asterisk/sdp_translator.h"
-#include "asterisk/sdp.h"
-#include "asterisk/vector.h"
-#include "asterisk/utils.h"
-#include "asterisk/stream.h"
-#include "sdp_private.h"
-
-void ast_sdp_a_free(struct ast_sdp_a_line *a_line)
-{
- ast_free(a_line);
-}
-
-void ast_sdp_a_lines_free(struct ast_sdp_a_lines *a_lines)
-{
- if (!a_lines) {
- return;
- }
-
- AST_VECTOR_CALLBACK_VOID(a_lines, ast_sdp_a_free);
- AST_VECTOR_FREE(a_lines);
- ast_free(a_lines);
-}
-
-void ast_sdp_c_free(struct ast_sdp_c_line *c_line)
-{
- ast_free(c_line);
-}
-
-void ast_sdp_payload_free(struct ast_sdp_payload *payload)
-{
- ast_free(payload);
-}
-
-void ast_sdp_payloads_free(struct ast_sdp_payloads *payloads)
-{
- if (!payloads) {
- return;
- }
-
- AST_VECTOR_CALLBACK_VOID(payloads, ast_sdp_payload_free);
- AST_VECTOR_FREE(payloads);
- ast_free(payloads);
-}
-
-void ast_sdp_m_free(struct ast_sdp_m_line *m_line)
-{
- if (!m_line) {
- return;
- }
-
- ast_sdp_a_lines_free(m_line->a_lines);
- ast_sdp_payloads_free(m_line->payloads);
- ast_sdp_c_free(m_line->c_line);
- ast_free(m_line);
-}
-
-void ast_sdp_m_lines_free(struct ast_sdp_m_lines *m_lines)
-{
- if (!m_lines) {
- return;
- }
-
- AST_VECTOR_CALLBACK_VOID(m_lines, ast_sdp_m_free);
- AST_VECTOR_FREE(m_lines);
- ast_free(m_lines);
-}
-
-void ast_sdp_o_free(struct ast_sdp_o_line *o_line)
-{
- ast_free(o_line);
-}
-
-void ast_sdp_s_free(struct ast_sdp_s_line *s_line)
-{
- ast_free(s_line);
-}
-
-void ast_sdp_t_free(struct ast_sdp_t_line *t_line)
-{
- ast_free(t_line);
-}
-
-static void ast_sdp_dtor(void *vdoomed)
-{
- struct ast_sdp *sdp = vdoomed;
-
- ast_sdp_o_free(sdp->o_line);
- ast_sdp_s_free(sdp->s_line);
- ast_sdp_c_free(sdp->c_line);
- ast_sdp_t_free(sdp->t_line);
- ast_sdp_a_lines_free(sdp->a_lines);
- ast_sdp_m_lines_free(sdp->m_lines);
-}
-
-#define COPY_STR_AND_ADVANCE(p, dest, source) \
-({ \
- dest = p; \
- strcpy(dest, source); \
- p += (strlen(source) + 1); \
-})
-
-struct ast_sdp_a_line *ast_sdp_a_alloc(const char *name, const char *value)
-{
- struct ast_sdp_a_line *a_line;
- size_t len;
- char *p;
-
- ast_assert(!ast_strlen_zero(name));
-
- if (ast_strlen_zero(value)) {
- value = "";
- }
-
- len = sizeof(*a_line) + strlen(name) + strlen(value) + 2;
- a_line = ast_calloc(1, len);
- if (!a_line) {
- return NULL;
- }
-
- p = ((char *)a_line) + sizeof(*a_line);
-
- COPY_STR_AND_ADVANCE(p, a_line->name, name);
- COPY_STR_AND_ADVANCE(p, a_line->value, value);
-
- return a_line;
-}
-
-struct ast_sdp_c_line *ast_sdp_c_alloc(const char *address_type, const char *address)
-{
- struct ast_sdp_c_line *c_line;
- size_t len;
- char *p;
-
- ast_assert(!ast_strlen_zero(address_type) && !ast_strlen_zero(address));
-
- len = sizeof(*c_line) + strlen(address_type) + strlen(address) + 2;
- c_line = ast_calloc(1, len);
- if (!c_line) {
- return NULL;
- }
-
- p = ((char *)c_line) + sizeof(*c_line);
-
- COPY_STR_AND_ADVANCE(p, c_line->address_type, address_type);
- COPY_STR_AND_ADVANCE(p, c_line->address, address);
-
- return c_line;
-}
-
-struct ast_sdp_payload *ast_sdp_payload_alloc(const char *fmt)
-{
- struct ast_sdp_payload *payload;
- size_t len;
-
- ast_assert(!ast_strlen_zero(fmt));
-
- len = sizeof(*payload) + strlen(fmt) + 1;
- payload = ast_calloc(1, len);
- if (!payload) {
- return NULL;
- }
-
- payload->fmt = ((char *)payload) + sizeof(*payload);
- strcpy(payload->fmt, fmt); /* Safe */
-
- return payload;
-}
-
-struct ast_sdp_m_line *ast_sdp_m_alloc(const char *type, uint16_t port,
- uint16_t port_count, const char *proto, struct ast_sdp_c_line *c_line)
-{
- struct ast_sdp_m_line *m_line;
- size_t len;
- char *p;
-
- ast_assert(!ast_strlen_zero(type) && !ast_strlen_zero(proto));
-
- len = sizeof(*m_line) + strlen(type) + strlen(proto) + 2;
- m_line = ast_calloc(1, len);
- if (!m_line) {
- return NULL;
- }
-
- m_line->a_lines = ast_calloc(1, sizeof(*m_line->a_lines));
- if (!m_line->a_lines) {
- ast_sdp_m_free(m_line);
- return NULL;
- }
- if (AST_VECTOR_INIT(m_line->a_lines, 20)) {
- ast_sdp_m_free(m_line);
- return NULL;
- }
-
- m_line->payloads = ast_calloc(1, sizeof(*m_line->payloads));
- if (!m_line->payloads) {
- ast_sdp_m_free(m_line);
- return NULL;
- }
- if (AST_VECTOR_INIT(m_line->payloads, 20)) {
- ast_sdp_m_free(m_line);
- return NULL;
- }
-
- p = ((char *)m_line) + sizeof(*m_line);
-
- COPY_STR_AND_ADVANCE(p, m_line->type, type);
- COPY_STR_AND_ADVANCE(p, m_line->proto, proto);
- m_line->port = port;
- m_line->port_count = port_count;
- m_line->c_line = c_line;
-
- return m_line;
-}
-
-struct ast_sdp_s_line *ast_sdp_s_alloc(const char *session_name)
-{
- struct ast_sdp_s_line *s_line;
- size_t len;
-
- if (ast_strlen_zero(session_name)) {
- session_name = " ";
- }
-
- len = sizeof(*s_line) + strlen(session_name) + 1;
- s_line = ast_calloc(1, len);
- if (!s_line) {
- return NULL;
- }
-
- s_line->session_name = ((char *)s_line) + sizeof(*s_line);
- strcpy(s_line->session_name, session_name); /* Safe */
-
- return s_line;
-}
-
-struct ast_sdp_t_line *ast_sdp_t_alloc(uint64_t start_time, uint64_t stop_time)
-{
- struct ast_sdp_t_line *t_line;
-
- t_line = ast_calloc(1, sizeof(*t_line));
- if (!t_line) {
- return NULL;
- }
-
- t_line->start_time = start_time;
- t_line->stop_time = stop_time;
-
- return t_line;
-}
-
-struct ast_sdp_o_line *ast_sdp_o_alloc(const char *username, uint64_t session_id,
- uint64_t session_version, const char *address_type, const char *address)
-{
- struct ast_sdp_o_line *o_line;
- size_t len;
- char *p;
-
- ast_assert(!ast_strlen_zero(username) && !ast_strlen_zero(address_type)
- && !ast_strlen_zero(address));
-
- len = sizeof(*o_line) + strlen(username) + strlen(address_type) + strlen(address) + 3;
- o_line = ast_calloc(1, len);
- if (!o_line) {
- return NULL;
- }
-
- o_line->session_id = session_id;
- o_line->session_version = session_version;
-
- p = ((char *)o_line) + sizeof(*o_line);
-
- COPY_STR_AND_ADVANCE(p, o_line->username, username);
- COPY_STR_AND_ADVANCE(p, o_line->address_type, address_type);
- COPY_STR_AND_ADVANCE(p, o_line->address, address);
-
- return o_line;
-}
-
-struct ast_sdp *ast_sdp_alloc(struct ast_sdp_o_line *o_line,
- struct ast_sdp_c_line *c_line, struct ast_sdp_s_line *s_line,
- struct ast_sdp_t_line *t_line)
-{
- struct ast_sdp *new_sdp;
-
- new_sdp = ao2_alloc_options(sizeof(*new_sdp), ast_sdp_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK);
- if (!new_sdp) {
- return NULL;
- }
-
- new_sdp->a_lines = ast_calloc(1, sizeof(*new_sdp->a_lines));
- if (!new_sdp->a_lines) {
- ao2_ref(new_sdp, -1);
- return NULL;
- }
- if (AST_VECTOR_INIT(new_sdp->a_lines, 20)) {
- ao2_ref(new_sdp, -1);
- return NULL;
- }
-
- new_sdp->m_lines = ast_calloc(1, sizeof(*new_sdp->m_lines));
- if (!new_sdp->m_lines) {
- ao2_ref(new_sdp, -1);
- return NULL;
- }
- if (AST_VECTOR_INIT(new_sdp->m_lines, 20)) {
- ao2_ref(new_sdp, -1);
- return NULL;
- }
-
- new_sdp->o_line = o_line;
- new_sdp->c_line = c_line;
- new_sdp->s_line = s_line;
- new_sdp->t_line = t_line;
-
- return new_sdp;
-}
-
-int ast_sdp_add_a(struct ast_sdp *sdp, struct ast_sdp_a_line *a_line)
-{
- ast_assert(sdp && a_line);
-
- return AST_VECTOR_APPEND(sdp->a_lines, a_line);
-}
-
-int ast_sdp_get_a_count(const struct ast_sdp *sdp)
-{
- ast_assert(sdp != NULL);
-
- return AST_VECTOR_SIZE(sdp->a_lines);
-}
-
-struct ast_sdp_a_line *ast_sdp_get_a(const struct ast_sdp *sdp, int index)
-{
- ast_assert(sdp != NULL);
-
- return AST_VECTOR_GET(sdp->a_lines, index);
-}
-
-int ast_sdp_add_m(struct ast_sdp *sdp, struct ast_sdp_m_line *m_line)
-{
- ast_assert(sdp && m_line);
-
- return AST_VECTOR_APPEND(sdp->m_lines, m_line);
-}
-
-int ast_sdp_get_m_count(const struct ast_sdp *sdp)
-{
- ast_assert(sdp != NULL);
-
- return AST_VECTOR_SIZE(sdp->m_lines);
-}
-
-struct ast_sdp_m_line *ast_sdp_get_m(const struct ast_sdp *sdp, int index)
-{
- ast_assert(sdp != NULL);
-
- return AST_VECTOR_GET(sdp->m_lines, index);
-}
-
-int ast_sdp_m_add_a(struct ast_sdp_m_line *m_line, struct ast_sdp_a_line *a_line)
-{
- ast_assert(m_line && a_line);
-
- return AST_VECTOR_APPEND(m_line->a_lines, a_line);
-}
-
-int ast_sdp_m_get_a_count(const struct ast_sdp_m_line *m_line)
-{
- ast_assert(m_line != NULL);
-
- return AST_VECTOR_SIZE(m_line->a_lines);
-}
-
-struct ast_sdp_a_line *ast_sdp_m_get_a(const struct ast_sdp_m_line *m_line, int index)
-{
- ast_assert(m_line != NULL);
-
- return AST_VECTOR_GET(m_line->a_lines, index);
-}
-
-int ast_sdp_m_add_payload(struct ast_sdp_m_line *m_line, struct ast_sdp_payload *payload)
-{
- ast_assert(m_line && payload);
-
- return AST_VECTOR_APPEND(m_line->payloads, payload);
-}
-
-int ast_sdp_m_get_payload_count(const struct ast_sdp_m_line *m_line)
-{
- ast_assert(m_line != NULL);
-
- return AST_VECTOR_SIZE(m_line->payloads);
-}
-
-struct ast_sdp_payload *ast_sdp_m_get_payload(const struct ast_sdp_m_line *m_line, int index)
-{
- ast_assert(m_line != NULL);
-
- return AST_VECTOR_GET(m_line->payloads, index);
-}
-
-static int sdp_m_add_fmtp(struct ast_sdp_m_line *m_line, const struct ast_format *format,
- int rtp_code)
-{
- struct ast_str *fmtp0 = ast_str_alloca(256);
- struct ast_sdp_a_line *a_line;
- char *tmp;
-
- ast_format_generate_sdp_fmtp(format, rtp_code, &fmtp0);
- if (ast_str_strlen(fmtp0) == 0) {
- /* Format doesn't have fmtp attributes */
- return 0;
- }
-
- tmp = ast_str_buffer(fmtp0) + ast_str_strlen(fmtp0) - 1;
- /* remove any carriage return line feeds */
- while (*tmp == '\r' || *tmp == '\n') --tmp;
- *++tmp = '\0';
-
- /*
- * ast...generate gives us everything, just need value
- *
- * It can also give multiple fmtp attribute lines. (silk does)
- */
- tmp = strchr(ast_str_buffer(fmtp0), ':');
- if (tmp && tmp[1] != '\0') {
- tmp++;
- } else {
- tmp = ast_str_buffer(fmtp0);
- }
-
- a_line = ast_sdp_a_alloc("fmtp", tmp);
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- return -1;
- }
-
- return 0;
-}
-
-static int sdp_m_add_rtpmap(struct ast_sdp_m_line *m_line,
- const struct ast_sdp_options *options, int rtp_code, int asterisk_format,
- const struct ast_format *format, int code)
-{
- char tmp[64];
- const char *enc_name;
- struct ast_sdp_payload *payload;
- struct ast_sdp_a_line *a_line;
-
- snprintf(tmp, sizeof(tmp), "%d", rtp_code);
- payload = ast_sdp_payload_alloc(tmp);
- if (!payload || ast_sdp_m_add_payload(m_line, payload)) {
- ast_sdp_payload_free(payload);
- return -1;
- }
-
- enc_name = ast_rtp_lookup_mime_subtype2(asterisk_format, format, code,
- options->g726_non_standard ? AST_RTP_OPT_G726_NONSTANDARD : 0);
-
- snprintf(tmp, sizeof(tmp), "%d %s/%d%s%s", rtp_code, enc_name,
- ast_rtp_lookup_sample_rate2(asterisk_format, format, code),
- strcmp(enc_name, "opus") ? "" : "/", strcmp(enc_name, "opus") ? "" : "2");
-
- a_line = ast_sdp_a_alloc("rtpmap", tmp);
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- return -1;
- }
-
- return 0;
-}
-
-int ast_sdp_m_add_format(struct ast_sdp_m_line *m_line, const struct ast_sdp_options *options,
- int rtp_code, int asterisk_format, const struct ast_format *format, int code)
-{
- return sdp_m_add_rtpmap(m_line, options, rtp_code, asterisk_format, format, code)
- || sdp_m_add_fmtp(m_line, format, rtp_code) ? -1 : 0;
-}
-
-static int sdp_find_a_common(const struct ast_sdp_a_lines *a_lines, int start,
- const char *attr_name, int payload)
-{
- struct ast_sdp_a_line *a_line;
- int idx;
-
- ast_assert(-1 <= start);
-
- for (idx = start + 1; idx < AST_VECTOR_SIZE(a_lines); ++idx) {
- int a_line_payload;
-
- a_line = AST_VECTOR_GET(a_lines, idx);
- if (strcmp(a_line->name, attr_name)) {
- continue;
- }
-
- if (payload >= 0) {
- int sscanf_res;
-
- sscanf_res = sscanf(a_line->value, "%30d", &a_line_payload);
- if (sscanf_res == 1 && payload == a_line_payload) {
- return idx;
- }
- } else {
- return idx;
- }
- }
-
- return -1;
-}
-
-int ast_sdp_find_a_first(const struct ast_sdp *sdp, const char *attr_name, int payload)
-{
- return sdp_find_a_common(sdp->a_lines, -1, attr_name, payload);
-}
-
-int ast_sdp_find_a_next(const struct ast_sdp *sdp, int last, const char *attr_name, int payload)
-{
- return sdp_find_a_common(sdp->a_lines, last, attr_name, payload);
-}
-
-struct ast_sdp_a_line *ast_sdp_find_attribute(const struct ast_sdp *sdp,
- const char *attr_name, int payload)
-{
- int idx;
-
- idx = ast_sdp_find_a_first(sdp, attr_name, payload);
- if (idx < 0) {
- return NULL;
- }
- return ast_sdp_get_a(sdp, idx);
-}
-
-int ast_sdp_m_find_a_first(const struct ast_sdp_m_line *m_line, const char *attr_name,
- int payload)
-{
- return sdp_find_a_common(m_line->a_lines, -1, attr_name, payload);
-}
-
-int ast_sdp_m_find_a_next(const struct ast_sdp_m_line *m_line, int last,
- const char *attr_name, int payload)
-{
- return sdp_find_a_common(m_line->a_lines, last, attr_name, payload);
-}
-
-struct ast_sdp_a_line *ast_sdp_m_find_attribute(const struct ast_sdp_m_line *m_line,
- const char *attr_name, int payload)
-{
- int idx;
-
- idx = ast_sdp_m_find_a_first(m_line, attr_name, payload);
- if (idx < 0) {
- return NULL;
- }
- return ast_sdp_m_get_a(m_line, idx);
-}
-
-struct ast_sdp_rtpmap *ast_sdp_rtpmap_alloc(int payload, const char *encoding_name,
- int clock_rate, const char *encoding_parameters)
-{
- struct ast_sdp_rtpmap *rtpmap;
- char *buf_pos;
-
- rtpmap = ast_calloc(1, sizeof(*rtpmap) + strlen(encoding_name) + strlen(encoding_parameters) + 2);
- if (!rtpmap) {
- return NULL;
- }
-
- rtpmap->payload = payload;
- rtpmap->clock_rate = clock_rate;
-
- buf_pos = rtpmap->buf;
- COPY_STR_AND_ADVANCE(buf_pos, rtpmap->encoding_name, encoding_name);
- COPY_STR_AND_ADVANCE(buf_pos, rtpmap->encoding_parameters, encoding_parameters);
-
- return rtpmap;
-}
-
-void ast_sdp_rtpmap_free(struct ast_sdp_rtpmap *rtpmap)
-{
- ast_free(rtpmap);
-}
-
-struct ast_sdp_rtpmap *ast_sdp_a_get_rtpmap(const struct ast_sdp_a_line *a_line)
-{
- char *value_copy;
- char *slash;
- int payload;
- char encoding_name[64];
- int clock_rate;
- char *encoding_parameters;
- struct ast_sdp_rtpmap *rtpmap;
- int clock_rate_len;
-
- value_copy = ast_strip(ast_strdupa(a_line->value));
-
- if (sscanf(value_copy, "%30d %63s", &payload, encoding_name) != 2) {
- return NULL;
- }
-
- slash = strchr(encoding_name, '/');
- if (!slash) {
- return NULL;
- }
- *slash++ = '\0';
- if (ast_strlen_zero(encoding_name)) {
- return NULL;
- }
- if (sscanf(slash, "%30d%n", &clock_rate, &clock_rate_len) < 1) {
- return NULL;
- }
-
- slash += clock_rate_len;
- if (!ast_strlen_zero(slash)) {
- if (*slash == '/') {
- *slash++ = '\0';
- encoding_parameters = slash;
- if (ast_strlen_zero(encoding_parameters)) {
- return NULL;
- }
- } else {
- return NULL;
- }
- } else {
- encoding_parameters = "";
- }
-
- rtpmap = ast_sdp_rtpmap_alloc(payload, encoding_name, clock_rate,
- encoding_parameters);
-
- return rtpmap;
-}
-
-/*!
- * \brief Turn an SDP attribute into an sdp_rtpmap structure
- *
- * \param m_line The media section where this attribute was found.
- * \param payload The RTP payload to find an rtpmap for
- * \param[out] rtpmap The rtpmap to fill in.
- * \return Zero if successful, otherwise less than zero
- */
-static struct ast_sdp_rtpmap *sdp_payload_get_rtpmap(const struct ast_sdp_m_line *m_line, int payload)
-{
- struct ast_sdp_a_line *rtpmap_attr;
-
- rtpmap_attr = ast_sdp_m_find_attribute(m_line, "rtpmap", payload);
- if (!rtpmap_attr) {
- return NULL;
- }
-
- return ast_sdp_a_get_rtpmap(rtpmap_attr);
-}
-
-static void process_fmtp_value(const char *value, int payload, struct ast_rtp_codecs *codecs)
-{
- char *param;
- char *param_start;
- char *param_end;
- size_t len;
- struct ast_format *replace;
- struct ast_format *format;
-
- /*
- * Extract the "a=fmtp:%d %s" attribute parameter string value which
- * starts after the colon.
- */
- param_start = ast_skip_nonblanks(value);/* Skip payload type */
- param_start = ast_skip_blanks(param_start);
- param_end = ast_skip_nonblanks(param_start);
- if (param_end == param_start) {
- /* There is no parameter string */
- return;
- }
- len = param_end - param_start;
- param = ast_alloca(len + 1);
- memcpy(param, param_start, len);
- param[len] = '\0';
-
- format = ast_rtp_codecs_get_payload_format(codecs, payload);
- if (!format) {
- return;
- }
-
- replace = ast_format_parse_sdp_fmtp(format, param);
- if (replace) {
- ast_rtp_codecs_payload_replace_format(codecs, payload, replace);
- ao2_ref(replace, -1);
- }
- ao2_ref(format, -1);
-}
-
-/*!
- * \brief Find and process all fmtp attribute lines for a given payload
- *
- * \param m_line The stream on which to search for the fmtp attributes
- * \param payload The specific fmtp attribute to search for
- * \param codecs The current RTP codecs that have been built up
- */
-static void process_fmtp_lines(const struct ast_sdp_m_line *m_line, int payload,
- struct ast_rtp_codecs *codecs)
-{
- const struct ast_sdp_a_line *a_line;
- int idx;
-
- idx = ast_sdp_m_find_a_first(m_line, "fmtp", payload);
- for (; 0 <= idx; idx = ast_sdp_m_find_a_next(m_line, idx, "fmtp", payload)) {
- a_line = ast_sdp_m_get_a(m_line, idx);
- ast_assert(a_line != NULL);
-
- process_fmtp_value(a_line->value, payload, codecs);
- }
-}
-
-/*!
- * \internal
- * \brief Determine the RTP stream direction in the given a lines.
- * \since 15.0.0
- *
- * \param a_lines Attribute lines to search.
- *
- * \retval Stream direction on success.
- * \retval AST_STREAM_STATE_REMOVED on failure.
- *
- * \return Nothing
- */
-static enum ast_stream_state get_a_line_direction(const struct ast_sdp_a_lines *a_lines)
-{
- if (a_lines) {
- enum ast_stream_state direction;
- int idx;
- const struct ast_sdp_a_line *a_line;
-
- for (idx = 0; idx < AST_VECTOR_SIZE(a_lines); ++idx) {
- a_line = AST_VECTOR_GET(a_lines, idx);
- direction = ast_stream_str2state(a_line->name);
- if (direction != AST_STREAM_STATE_REMOVED) {
- return direction;
- }
- }
- }
-
- return AST_STREAM_STATE_REMOVED;
-}
-
-/*!
- * \internal
- * \brief Determine the RTP stream direction.
- * \since 15.0.0
- *
- * \param a_lines The SDP media global attributes
- * \param m_line The SDP media section to convert
- *
- * \return Stream direction
- */
-static enum ast_stream_state get_stream_direction(const struct ast_sdp_a_lines *a_lines, const struct ast_sdp_m_line *m_line)
-{
- enum ast_stream_state direction;
-
- direction = get_a_line_direction(m_line->a_lines);
- if (direction != AST_STREAM_STATE_REMOVED) {
- return direction;
- }
- direction = get_a_line_direction(a_lines);
- if (direction != AST_STREAM_STATE_REMOVED) {
- return direction;
- }
- return AST_STREAM_STATE_SENDRECV;
-}
-
-/*
- * Needed so we don't have an external function referenced as data.
- * The dynamic linker doesn't handle that very well.
- */
-static void rtp_codecs_free(struct ast_rtp_codecs *codecs)
-{
- if (codecs) {
- ast_rtp_codecs_payloads_destroy(codecs);
- }
-}
-
-/*!
- * \brief Convert an SDP stream into an Asterisk stream
- *
- * Given an m-line from an SDP, convert it into an ast_stream structure.
- * This takes formats, as well as clock-rate and fmtp attributes into account.
- *
- * \param a_lines The SDP media global attributes
- * \param m_line The SDP media section to convert
- * \param g726_non_standard Non-zero if G.726 is non-standard
- *
- * \retval NULL An error occurred
- * \retval non-NULL The converted stream
- */
-static struct ast_stream *get_stream_from_m(const struct ast_sdp_a_lines *a_lines, const struct ast_sdp_m_line *m_line, int g726_non_standard)
-{
- int i;
- int non_ast_fmts;
- struct ast_rtp_codecs *codecs;
- struct ast_format_cap *caps;
- struct ast_stream *stream;
- enum ast_rtp_options options;
-
- caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- if (!caps) {
- return NULL;
- }
- stream = ast_stream_alloc(m_line->type, ast_media_type_from_str(m_line->type));
- if (!stream) {
- ao2_ref(caps, -1);
- return NULL;
- }
-
- switch (ast_stream_get_type(stream)) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- codecs = ast_calloc(1, sizeof(*codecs));
- if (!codecs || ast_rtp_codecs_payloads_initialize(codecs)) {
- rtp_codecs_free(codecs);
- ast_stream_free(stream);
- ao2_ref(caps, -1);
- ast_free(codecs);
- return NULL;
- }
- ast_stream_set_data(stream, AST_STREAM_DATA_RTP_CODECS, codecs,
- (ast_stream_data_free_fn) rtp_codecs_free);
-
- if (!m_line->port) {
- /* Stream is declined. There may not be any attributes. */
- ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);
- break;
- }
-
- options = g726_non_standard ? AST_RTP_OPT_G726_NONSTANDARD : 0;
- for (i = 0; i < ast_sdp_m_get_payload_count(m_line); ++i) {
- struct ast_sdp_payload *payload_s;
- struct ast_sdp_rtpmap *rtpmap;
- int payload;
-
- payload_s = ast_sdp_m_get_payload(m_line, i);
- sscanf(payload_s->fmt, "%30d", &payload);
-
- rtpmap = sdp_payload_get_rtpmap(m_line, payload);
- if (!rtpmap) {
- /* No rtpmap attribute. Try static payload type format assignment */
- ast_rtp_codecs_payloads_set_m_type(codecs, NULL, payload);
- continue;
- }
-
- if (!ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, NULL, payload,
- m_line->type, rtpmap->encoding_name, options, rtpmap->clock_rate)) {
- /* Successfully mapped the payload type to format */
- process_fmtp_lines(m_line, payload, codecs);
- }
- ast_sdp_rtpmap_free(rtpmap);
- }
-
- ast_rtp_codecs_payload_formats(codecs, caps, &non_ast_fmts);
-
- ast_stream_set_state(stream, get_stream_direction(a_lines, m_line));
- break;
- case AST_MEDIA_TYPE_IMAGE:
- if (!m_line->port) {
- /* Stream is declined. There may not be any attributes. */
- ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);
- break;
- }
-
- for (i = 0; i < ast_sdp_m_get_payload_count(m_line); ++i) {
- struct ast_sdp_payload *payload;
-
- /* As we don't carry T.38 over RTP we do our own format check */
- payload = ast_sdp_m_get_payload(m_line, i);
- if (!strcasecmp(payload->fmt, "t38")) {
- ast_format_cap_append(caps, ast_format_t38, 0);
- ast_stream_set_state(stream, AST_STREAM_STATE_SENDRECV);
- }
- }
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- /* Consider these unsupported streams as declined */
- ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);
- break;
- }
-
- ast_stream_set_formats(stream, caps);
- ao2_ref(caps, -1);
-
- return stream;
-}
-
-struct ast_stream_topology *ast_get_topology_from_sdp(const struct ast_sdp *sdp, int g726_non_standard)
-{
- struct ast_stream_topology *topology;
- int i;
-
- topology = ast_stream_topology_alloc();
- if (!topology) {
- return NULL;
- }
-
- for (i = 0; i < ast_sdp_get_m_count(sdp); ++i) {
- struct ast_stream *stream;
-
- stream = get_stream_from_m(sdp->a_lines, ast_sdp_get_m(sdp, i), g726_non_standard);
- if (!stream) {
- /*
- * The topology cannot match the SDP because
- * we failed to create a corresponding stream.
- */
- ast_stream_topology_free(topology);
- return NULL;
- }
- if (ast_stream_topology_append_stream(topology, stream) < 0) {
- /* Failed to add stream to topology */
- ast_stream_free(stream);
- ast_stream_topology_free(topology);
- return NULL;
- }
- }
-
- return topology;
-}
diff --git a/main/sdp_options.c b/main/sdp_options.c
deleted file mode 100644
index 79efbafa0..000000000
--- a/main/sdp_options.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#include "asterisk.h"
-
-#include "asterisk/utils.h"
-#include "asterisk/sdp_options.h"
-
-#include "sdp_private.h"
-
-#define DEFAULT_DTMF AST_SDP_DTMF_NONE
-#define DEFAULT_ICE AST_SDP_ICE_DISABLED
-#define DEFAULT_IMPL AST_SDP_IMPL_STRING
-#define DEFAULT_ENCRYPTION AST_SDP_ENCRYPTION_DISABLED
-#define DEFAULT_MAX_STREAMS 16 /* Set to match our PJPROJECT PJMEDIA_MAX_SDP_MEDIA. */
-
-#define DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(field, assert_on_null) \
-void ast_sdp_options_set_##field(struct ast_sdp_options *options, const char *value) \
-{ \
- ast_assert(options != NULL); \
- if ((assert_on_null)) ast_assert(!ast_strlen_zero(value)); \
- if (!strcmp(value, options->field)) return; \
- ast_string_field_set(options, field, value); \
-} \
-const char *ast_sdp_options_get_##field(const struct ast_sdp_options *options) \
-{ \
- ast_assert(options != NULL); \
- return options->field; \
-} \
-
-#define DEFINE_GETTERS_SETTERS_FOR(type, field) \
-void ast_sdp_options_set_##field(struct ast_sdp_options *options, type value) \
-{ \
- ast_assert(options != NULL); \
- options->field = value; \
-} \
-type ast_sdp_options_get_##field(const struct ast_sdp_options *options) \
-{ \
- ast_assert(options != NULL); \
- return options->field; \
-} \
-
-DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(media_address, 0);
-DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(interface_address, 0);
-DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(sdpowner, 0);
-DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(sdpsession, 0);
-DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(rtp_engine, 0);
-
-DEFINE_GETTERS_SETTERS_FOR(void *, state_context);
-DEFINE_GETTERS_SETTERS_FOR(ast_sdp_answerer_modify_cb, answerer_modify_cb);
-DEFINE_GETTERS_SETTERS_FOR(ast_sdp_offerer_modify_cb, offerer_modify_cb);
-DEFINE_GETTERS_SETTERS_FOR(ast_sdp_offerer_config_cb, offerer_config_cb);
-DEFINE_GETTERS_SETTERS_FOR(ast_sdp_preapply_cb, preapply_cb);
-DEFINE_GETTERS_SETTERS_FOR(ast_sdp_postapply_cb, postapply_cb);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtp_symmetric);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, udptl_symmetric);
-DEFINE_GETTERS_SETTERS_FOR(enum ast_t38_ec_modes, udptl_error_correction);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, udptl_far_max_datagram);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtp_ipv6);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, g726_non_standard);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtcp_mux);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, tos_audio);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, cos_audio);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, tos_video);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, cos_video);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, max_streams);
-DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_dtmf, dtmf);
-DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_ice, ice);
-DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_impl, impl);
-DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_encryption, encryption);
-DEFINE_GETTERS_SETTERS_FOR(unsigned int, ssrc);
-
-struct ast_sched_context *ast_sdp_options_get_sched_type(const struct ast_sdp_options *options, enum ast_media_type type)
-{
- struct ast_sched_context *sched = NULL;
-
- switch (type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- case AST_MEDIA_TYPE_IMAGE:
- case AST_MEDIA_TYPE_TEXT:
- sched = options->sched[type];
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_END:
- break;
- }
- return sched;
-}
-
-void ast_sdp_options_set_sched_type(struct ast_sdp_options *options, enum ast_media_type type, struct ast_sched_context *sched)
-{
- switch (type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- case AST_MEDIA_TYPE_IMAGE:
- case AST_MEDIA_TYPE_TEXT:
- options->sched[type] = sched;
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_END:
- break;
- }
-}
-
-struct ast_format_cap *ast_sdp_options_get_format_cap_type(const struct ast_sdp_options *options,
- enum ast_media_type type)
-{
- struct ast_format_cap *cap = NULL;
-
- switch (type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- case AST_MEDIA_TYPE_IMAGE:
- case AST_MEDIA_TYPE_TEXT:
- cap = options->caps[type];
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_END:
- break;
- }
- return cap;
-}
-
-void ast_sdp_options_set_format_cap_type(struct ast_sdp_options *options,
- enum ast_media_type type, struct ast_format_cap *cap)
-{
- switch (type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- case AST_MEDIA_TYPE_IMAGE:
- case AST_MEDIA_TYPE_TEXT:
- ao2_cleanup(options->caps[type]);
- options->caps[type] = NULL;
- if (cap && !ast_format_cap_empty(cap)) {
- ao2_ref(cap, +1);
- options->caps[type] = cap;
- }
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_END:
- break;
- }
-}
-
-void ast_sdp_options_set_format_caps(struct ast_sdp_options *options,
- struct ast_format_cap *cap)
-{
- enum ast_media_type type;
-
- for (type = AST_MEDIA_TYPE_UNKNOWN; type < AST_MEDIA_TYPE_END; ++type) {
- ao2_cleanup(options->caps[type]);
- options->caps[type] = NULL;
- }
-
- if (!cap || ast_format_cap_empty(cap)) {
- return;
- }
-
- for (type = AST_MEDIA_TYPE_UNKNOWN + 1; type < AST_MEDIA_TYPE_END; ++type) {
- struct ast_format_cap *type_cap;
-
- type_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- if (!type_cap) {
- continue;
- }
-
- ast_format_cap_set_framing(type_cap, ast_format_cap_get_framing(cap));
- if (ast_format_cap_append_from_cap(type_cap, cap, type)
- || ast_format_cap_empty(type_cap)) {
- ao2_ref(type_cap, -1);
- continue;
- }
-
- /* This takes the allocation reference */
- options->caps[type] = type_cap;
- }
-}
-
-static void set_defaults(struct ast_sdp_options *options)
-{
- options->dtmf = DEFAULT_DTMF;
- options->ice = DEFAULT_ICE;
- options->impl = DEFAULT_IMPL;
- options->encryption = DEFAULT_ENCRYPTION;
- options->max_streams = DEFAULT_MAX_STREAMS;
-}
-
-struct ast_sdp_options *ast_sdp_options_alloc(void)
-{
- struct ast_sdp_options *options;
-
- options = ast_calloc(1, sizeof(*options));
- if (!options) {
- return NULL;
- }
-
- if (ast_string_field_init(options, 256)) {
- ast_free(options);
- return NULL;
- }
-
- set_defaults(options);
- return options;
-}
-
-void ast_sdp_options_free(struct ast_sdp_options *options)
-{
- enum ast_media_type type;
-
- if (!options) {
- return;
- }
-
- for (type = AST_MEDIA_TYPE_UNKNOWN; type < AST_MEDIA_TYPE_END; ++type) {
- ao2_cleanup(options->caps[type]);
- }
- ast_string_field_free_memory(options);
- ast_free(options);
-}
diff --git a/main/sdp_private.h b/main/sdp_private.h
deleted file mode 100644
index 48bedc802..000000000
--- a/main/sdp_private.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#ifndef _MAIN_SDP_PRIVATE_H
-#define _MAIN_SDP_PRIVATE_H
-
-#include "asterisk/stringfields.h"
-#include "asterisk/sdp_options.h"
-
-struct ast_sdp_options {
- AST_DECLARE_STRING_FIELDS(
- /*! Media address to advertise in SDP session c= line */
- AST_STRING_FIELD(media_address);
- /*! Optional address of the interface media should use. */
- AST_STRING_FIELD(interface_address);
- /*! SDP origin username */
- AST_STRING_FIELD(sdpowner);
- /*! SDP session name */
- AST_STRING_FIELD(sdpsession);
- /*! RTP Engine Name */
- AST_STRING_FIELD(rtp_engine);
- );
- /*! Scheduler context for the media stream types (Mainly for RTP) */
- struct ast_sched_context *sched[AST_MEDIA_TYPE_END];
- /*! Capabilities to create new streams of the indexed media type. */
- struct ast_format_cap *caps[AST_MEDIA_TYPE_END];
- /*! User supplied context data pointer for the SDP state. */
- void *state_context;
- /*! Modify negotiated topology before create answer SDP callback. */
- ast_sdp_answerer_modify_cb answerer_modify_cb;
- /*! Modify proposed topology before create offer SDP callback. */
- ast_sdp_offerer_modify_cb offerer_modify_cb;
- /*! Configure proposed topology extra stream options before create offer SDP callback. */
- ast_sdp_offerer_config_cb offerer_config_cb;
- /*! Negotiated topology is about to be applied callback. */
- ast_sdp_preapply_cb preapply_cb;
- /*! Negotiated topology was just applied callback. */
- ast_sdp_postapply_cb postapply_cb;
- struct {
- unsigned int rtp_symmetric:1;
- unsigned int udptl_symmetric:1;
- unsigned int rtp_ipv6:1;
- unsigned int g726_non_standard:1;
- unsigned int rtcp_mux:1;
- unsigned int ssrc:1;
- };
- struct {
- unsigned int tos_audio;
- unsigned int cos_audio;
- unsigned int tos_video;
- unsigned int cos_video;
- unsigned int udptl_far_max_datagram;
- /*! Maximum number of streams to allow. */
- unsigned int max_streams;
- };
- enum ast_sdp_options_dtmf dtmf;
- enum ast_sdp_options_ice ice;
- enum ast_sdp_options_impl impl;
- enum ast_sdp_options_encryption encryption;
- enum ast_t38_ec_modes udptl_error_correction;
-};
-
-#endif /* _MAIN_SDP_PRIVATE_H */
diff --git a/main/sdp_state.c b/main/sdp_state.c
deleted file mode 100644
index 5f9ad5eb9..000000000
--- a/main/sdp_state.c
+++ /dev/null
@@ -1,3411 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#include "asterisk.h"
-#include "asterisk/sdp_state.h"
-#include "asterisk/sdp_options.h"
-#include "asterisk/sdp_translator.h"
-#include "asterisk/vector.h"
-#include "asterisk/utils.h"
-#include "asterisk/netsock2.h"
-#include "asterisk/rtp_engine.h"
-#include "asterisk/format.h"
-#include "asterisk/format_cap.h"
-#include "asterisk/config.h"
-#include "asterisk/codec.h"
-#include "asterisk/udptl.h"
-
-#include "asterisk/sdp.h"
-#include "asterisk/stream.h"
-
-#include "sdp_private.h"
-
-enum ast_sdp_role {
- /*!
- * \brief The role has not yet been determined.
- *
- * When the SDP state is allocated, this is the starting role.
- * Similarly, when the SDP state is reset, the role is reverted
- * to this.
- */
- SDP_ROLE_NOT_SET,
- /*!
- * \brief We are the offerer.
- *
- * If a local SDP is requested before a remote SDP has been set, then
- * we assume the role of offerer. This means that we will generate an
- * SDP from the local capabilities and configured options.
- */
- SDP_ROLE_OFFERER,
- /*!
- * \brief We are the answerer.
- *
- * If a remote SDP is set before a local SDP is requested, then we
- * assume the role of answerer. This means that we will generate an
- * SDP based on a merge of the remote capabilities and our local capabilities.
- */
- SDP_ROLE_ANSWERER,
-};
-
-typedef int (*state_fn)(struct ast_sdp_state *state);
-
-struct sdp_state_rtp {
- /*! The underlying RTP instance */
- struct ast_rtp_instance *instance;
-};
-
-struct sdp_state_udptl {
- /*! The underlying UDPTL instance */
- struct ast_udptl *instance;
-};
-
-struct sdp_state_stream {
- /*! Type of the stream */
- enum ast_media_type type;
- union {
- /*! The underlying RTP instance */
- struct sdp_state_rtp *rtp;
- /*! The underlying UDPTL instance */
- struct sdp_state_udptl *udptl;
- };
- /*! An explicit connection address for this stream */
- struct ast_sockaddr connection_address;
- /*!
- * \brief Stream is on hold by remote side
- *
- * \note This flag is never set on the
- * sdp_state->proposed_capabilities->streams states. This is useful
- * when the remote sends us a reINVITE with a deferred SDP to place
- * us on and off of hold.
- */
- unsigned int remotely_held:1;
- /*! Stream is on hold by local side */
- unsigned int locally_held:1;
- /*! UDPTL session parameters */
- struct ast_control_t38_parameters t38_local_params;
-};
-
-static int sdp_is_stream_type_supported(enum ast_media_type type)
-{
- int is_supported = 0;
-
- switch (type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- case AST_MEDIA_TYPE_IMAGE:
- is_supported = 1;
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- break;
- }
- return is_supported;
-}
-
-static void sdp_state_rtp_destroy(void *obj)
-{
- struct sdp_state_rtp *rtp = obj;
-
- if (rtp->instance) {
- ast_rtp_instance_stop(rtp->instance);
- ast_rtp_instance_destroy(rtp->instance);
- }
-}
-
-static void sdp_state_udptl_destroy(void *obj)
-{
- struct sdp_state_udptl *udptl = obj;
-
- if (udptl->instance) {
- ast_udptl_destroy(udptl->instance);
- }
-}
-
-static void sdp_state_stream_free(struct sdp_state_stream *state_stream)
-{
- switch (state_stream->type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- ao2_cleanup(state_stream->rtp);
- break;
- case AST_MEDIA_TYPE_IMAGE:
- ao2_cleanup(state_stream->udptl);
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- break;
- }
- ast_free(state_stream);
-}
-
-AST_VECTOR(sdp_state_streams, struct sdp_state_stream *);
-
-struct sdp_state_capabilities {
- /*! Stream topology */
- struct ast_stream_topology *topology;
- /*! Additional information about the streams */
- struct sdp_state_streams streams;
-};
-
-static void sdp_state_capabilities_free(struct sdp_state_capabilities *capabilities)
-{
- if (!capabilities) {
- return;
- }
-
- ast_stream_topology_free(capabilities->topology);
- AST_VECTOR_CALLBACK_VOID(&capabilities->streams, sdp_state_stream_free);
- AST_VECTOR_FREE(&capabilities->streams);
- ast_free(capabilities);
-}
-
-/*! \brief Internal function which creates an RTP instance */
-static struct sdp_state_rtp *create_rtp(const struct ast_sdp_options *options,
- enum ast_media_type media_type)
-{
- struct sdp_state_rtp *rtp;
- struct ast_rtp_engine_ice *ice;
- static struct ast_sockaddr address_rtp;
- struct ast_sockaddr *media_address = &address_rtp;
-
- if (!ast_strlen_zero(options->interface_address)) {
- if (!ast_sockaddr_parse(&address_rtp, options->interface_address, 0)) {
- ast_log(LOG_ERROR, "Attempted to bind RTP to invalid media address: %s\n",
- options->interface_address);
- return NULL;
- }
- } else {
- if (ast_check_ipv6()) {
- ast_sockaddr_parse(&address_rtp, "::", 0);
- } else {
- ast_sockaddr_parse(&address_rtp, "0.0.0.0", 0);
- }
- }
-
- rtp = ao2_alloc_options(sizeof(*rtp), sdp_state_rtp_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
- if (!rtp) {
- return NULL;
- }
-
- rtp->instance = ast_rtp_instance_new(options->rtp_engine,
- ast_sdp_options_get_sched_type(options, media_type), media_address, NULL);
- if (!rtp->instance) {
- ast_log(LOG_ERROR, "Unable to create RTP instance using RTP engine '%s'\n",
- options->rtp_engine);
- ao2_ref(rtp, -1);
- return NULL;
- }
-
- ast_rtp_instance_set_prop(rtp->instance, AST_RTP_PROPERTY_RTCP,
- AST_RTP_INSTANCE_RTCP_STANDARD);
- ast_rtp_instance_set_prop(rtp->instance, AST_RTP_PROPERTY_NAT,
- options->rtp_symmetric);
-
- if (options->ice == AST_SDP_ICE_DISABLED
- && (ice = ast_rtp_instance_get_ice(rtp->instance))) {
- ice->stop(rtp->instance);
- }
-
- if (options->dtmf == AST_SDP_DTMF_RFC_4733 || options->dtmf == AST_SDP_DTMF_AUTO) {
- ast_rtp_instance_dtmf_mode_set(rtp->instance, AST_RTP_DTMF_MODE_RFC2833);
- ast_rtp_instance_set_prop(rtp->instance, AST_RTP_PROPERTY_DTMF, 1);
- } else if (options->dtmf == AST_SDP_DTMF_INBAND) {
- ast_rtp_instance_dtmf_mode_set(rtp->instance, AST_RTP_DTMF_MODE_INBAND);
- }
-
- switch (media_type) {
- case AST_MEDIA_TYPE_AUDIO:
- if (options->tos_audio || options->cos_audio) {
- ast_rtp_instance_set_qos(rtp->instance, options->tos_audio,
- options->cos_audio, "SIP RTP Audio");
- }
- break;
- case AST_MEDIA_TYPE_VIDEO:
- if (options->tos_video || options->cos_video) {
- ast_rtp_instance_set_qos(rtp->instance, options->tos_video,
- options->cos_video, "SIP RTP Video");
- }
- break;
- case AST_MEDIA_TYPE_IMAGE:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_END:
- break;
- }
-
- ast_rtp_instance_set_last_rx(rtp->instance, time(NULL));
-
- return rtp;
-}
-
-/*! \brief Internal function which creates a UDPTL instance */
-static struct sdp_state_udptl *create_udptl(const struct ast_sdp_options *options)
-{
- struct sdp_state_udptl *udptl;
- static struct ast_sockaddr address_udptl;
- struct ast_sockaddr *media_address = &address_udptl;
-
- if (!ast_strlen_zero(options->interface_address)) {
- if (!ast_sockaddr_parse(&address_udptl, options->interface_address, 0)) {
- ast_log(LOG_ERROR, "Attempted to bind UDPTL to invalid media address: %s\n",
- options->interface_address);
- return NULL;
- }
- } else {
- if (ast_check_ipv6()) {
- ast_sockaddr_parse(&address_udptl, "::", 0);
- } else {
- ast_sockaddr_parse(&address_udptl, "0.0.0.0", 0);
- }
- }
-
- udptl = ao2_alloc_options(sizeof(*udptl), sdp_state_udptl_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
- if (!udptl) {
- return NULL;
- }
-
- udptl->instance = ast_udptl_new_with_bindaddr(NULL, NULL, 0, media_address);
- if (!udptl->instance) {
- ao2_ref(udptl, -1);
- return NULL;
- }
-
- ast_udptl_set_error_correction_scheme(udptl->instance, ast_sdp_options_get_udptl_error_correction(options));
- ast_udptl_setnat(udptl->instance, ast_sdp_options_get_udptl_symmetric(options));
- ast_udptl_set_far_max_datagram(udptl->instance, ast_sdp_options_get_udptl_far_max_datagram(options));
-
- return udptl;
-}
-
-static struct ast_stream *merge_local_stream(const struct ast_sdp_options *options,
- const struct ast_stream *update);
-
-static struct sdp_state_capabilities *sdp_initialize_state_capabilities(const struct ast_stream_topology *topology,
- const struct ast_sdp_options *options)
-{
- struct sdp_state_capabilities *capabilities;
- struct ast_stream *stream;
- unsigned int topology_count;
- unsigned int max_streams;
- unsigned int idx;
-
- capabilities = ast_calloc(1, sizeof(*capabilities));
- if (!capabilities) {
- return NULL;
- }
-
- capabilities->topology = ast_stream_topology_alloc();
- if (!capabilities->topology) {
- sdp_state_capabilities_free(capabilities);
- return NULL;
- }
-
- max_streams = ast_sdp_options_get_max_streams(options);
- if (topology) {
- topology_count = ast_stream_topology_get_count(topology);
- } else {
- topology_count = 0;
- }
-
- /* Gather acceptable streams from the initial topology */
- for (idx = 0; idx < topology_count; ++idx) {
- stream = ast_stream_topology_get_stream(topology, idx);
- if (!sdp_is_stream_type_supported(ast_stream_get_type(stream))) {
- /* Delete the unsupported stream from the initial topology */
- continue;
- }
- if (max_streams <= ast_stream_topology_get_count(capabilities->topology)) {
- /* Cannot support any more streams */
- break;
- }
-
- stream = merge_local_stream(options, stream);
- if (!stream) {
- sdp_state_capabilities_free(capabilities);
- return NULL;
- }
-
- if (ast_stream_topology_append_stream(capabilities->topology, stream) < 0) {
- ast_stream_free(stream);
- sdp_state_capabilities_free(capabilities);
- return NULL;
- }
- }
-
- /*
- * Remove trailing declined streams from the initial built topology.
- * No need to waste space in the SDP with these unused slots.
- */
- for (idx = ast_stream_topology_get_count(capabilities->topology); idx--;) {
- stream = ast_stream_topology_get_stream(capabilities->topology, idx);
- if (ast_stream_get_state(stream) != AST_STREAM_STATE_REMOVED) {
- break;
- }
- ast_stream_topology_del_stream(capabilities->topology, idx);
- }
-
- topology_count = ast_stream_topology_get_count(capabilities->topology);
- if (AST_VECTOR_INIT(&capabilities->streams, topology_count)) {
- sdp_state_capabilities_free(capabilities);
- return NULL;
- }
-
- for (idx = 0; idx < topology_count; ++idx) {
- struct sdp_state_stream *state_stream;
-
- state_stream = ast_calloc(1, sizeof(*state_stream));
- if (!state_stream) {
- sdp_state_capabilities_free(capabilities);
- return NULL;
- }
-
- stream = ast_stream_topology_get_stream(capabilities->topology, idx);
- state_stream->type = ast_stream_get_type(stream);
- if (ast_stream_get_state(stream) != AST_STREAM_STATE_REMOVED) {
- switch (state_stream->type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- state_stream->rtp = create_rtp(options, state_stream->type);
- if (!state_stream->rtp) {
- sdp_state_stream_free(state_stream);
- sdp_state_capabilities_free(capabilities);
- return NULL;
- }
- break;
- case AST_MEDIA_TYPE_IMAGE:
- state_stream->udptl = create_udptl(options);
- if (!state_stream->udptl) {
- sdp_state_stream_free(state_stream);
- sdp_state_capabilities_free(capabilities);
- return NULL;
- }
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- /* Unsupported stream type already handled earlier */
- ast_assert(0);
- break;
- }
- }
-
- if (AST_VECTOR_APPEND(&capabilities->streams, state_stream)) {
- sdp_state_stream_free(state_stream);
- sdp_state_capabilities_free(capabilities);
- return NULL;
- }
- }
-
- return capabilities;
-}
-
-/*!
- * \brief SDP state, the main structure used to keep track of SDP negotiation
- * and settings.
- *
- * Most fields are pretty self-explanatory, but negotiated_capabilities and
- * proposed_capabilities could use some further explanation. When an SDP
- * state is allocated, a stream topology is provided that dictates the
- * types of streams to offer in the resultant SDP. At the time the SDP
- * is allocated, this topology is used to create the proposed_capabilities.
- *
- * If we are the SDP offerer, then the proposed_capabilities are what are used
- * to generate the offer SDP. When the answer SDP arrives, the proposed capabilities
- * are merged with the answer SDP to create the negotiated capabilities.
- *
- * If we are the SDP answerer, then the incoming offer SDP is merged with our
- * proposed capabilities to create the negotiated capabilities. These negotiated
- * capabilities are what we send in our answer SDP.
- *
- * Any changes that a user of the API performs will occur on the proposed capabilities.
- * The negotiated capabilities are only altered based on actual SDP negotiation. This is
- * done so that the negotiated capabilities can be fallen back on if the proposed
- * capabilities run into some sort of issue.
- */
-struct ast_sdp_state {
- /*! Current capabilities */
- struct sdp_state_capabilities *negotiated_capabilities;
- /*! Proposed capabilities */
- struct sdp_state_capabilities *proposed_capabilities;
- /*!
- * \brief New topology waiting to be merged.
- *
- * \details
- * Repeated topology updates are merged into each other here until
- * negotiations are restarted and we create an offer.
- */
- struct ast_stream_topology *pending_topology_update;
- /*! Local SDP. Generated via the options and negotiated/proposed capabilities. */
- struct ast_sdp *local_sdp;
- /*! Saved remote SDP */
- struct ast_sdp *remote_sdp;
- /*! SDP options. Configured options beyond media capabilities. */
- struct ast_sdp_options *options;
- /*! Translator that puts SDPs into the expected representation */
- struct ast_sdp_translator *translator;
- /*! An explicit global connection address */
- struct ast_sockaddr connection_address;
- /*! The role that we occupy in SDP negotiation */
- enum ast_sdp_role role;
- /*! TRUE if all streams on hold by local side */
- unsigned int locally_held:1;
- /*! TRUE if the remote offer resulted in all streams being declined. */
- unsigned int remote_offer_rejected:1;
-};
-
-struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *topology,
- struct ast_sdp_options *options)
-{
- struct ast_sdp_state *sdp_state;
-
- sdp_state = ast_calloc(1, sizeof(*sdp_state));
- if (!sdp_state) {
- return NULL;
- }
-
- sdp_state->options = options;
-
- sdp_state->translator = ast_sdp_translator_new(ast_sdp_options_get_impl(sdp_state->options));
- if (!sdp_state->translator) {
- ast_sdp_state_free(sdp_state);
- return NULL;
- }
-
- sdp_state->proposed_capabilities = sdp_initialize_state_capabilities(topology, options);
- if (!sdp_state->proposed_capabilities) {
- ast_sdp_state_free(sdp_state);
- return NULL;
- }
-
- sdp_state->role = SDP_ROLE_NOT_SET;
-
- return sdp_state;
-}
-
-void ast_sdp_state_free(struct ast_sdp_state *sdp_state)
-{
- if (!sdp_state) {
- return;
- }
-
- sdp_state_capabilities_free(sdp_state->negotiated_capabilities);
- sdp_state_capabilities_free(sdp_state->proposed_capabilities);
- ao2_cleanup(sdp_state->local_sdp);
- ao2_cleanup(sdp_state->remote_sdp);
- ast_sdp_options_free(sdp_state->options);
- ast_sdp_translator_free(sdp_state->translator);
- ast_free(sdp_state);
-}
-
-/*!
- * \internal
- * \brief Allow a configured callback to alter the new negotiated joint topology.
- * \since 15.0.0
- *
- * \details
- * The callback can alter topology stream names, formats, or decline streams.
- *
- * \param sdp_state
- * \param topology Joint topology that we intend to generate the answer SDP.
- *
- * \return Nothing
- */
-static void sdp_state_cb_answerer_modify_topology(const struct ast_sdp_state *sdp_state,
- struct ast_stream_topology *topology)
-{
- ast_sdp_answerer_modify_cb cb;
-
- cb = ast_sdp_options_get_answerer_modify_cb(sdp_state->options);
- if (cb) {
- void *context;
- const struct ast_stream_topology *neg_topology;/*!< Last negotiated topology */
-#ifdef AST_DEVMODE
- struct ast_stream *stream;
- int idx;
- enum ast_media_type type[ast_stream_topology_get_count(topology)];
- enum ast_stream_state state[ast_stream_topology_get_count(topology)];
-
- /*
- * Save stream types and states to validate that they don't
- * get changed unexpectedly.
- */
- for (idx = 0; idx < ast_stream_topology_get_count(topology); ++idx) {
- stream = ast_stream_topology_get_stream(topology, idx);
- type[idx] = ast_stream_get_type(stream);
- state[idx] = ast_stream_get_state(stream);
- }
-#endif
-
- context = ast_sdp_options_get_state_context(sdp_state->options);
- neg_topology = sdp_state->negotiated_capabilities
- ? sdp_state->negotiated_capabilities->topology : NULL;
- cb(context, neg_topology, topology);
-
-#ifdef AST_DEVMODE
- for (idx = 0; idx < ast_stream_topology_get_count(topology); ++idx) {
- stream = ast_stream_topology_get_stream(topology, idx);
-
- /* Check that active streams have at least one format */
- ast_assert(ast_stream_get_state(stream) == AST_STREAM_STATE_REMOVED
- || (ast_stream_get_formats(stream)
- && ast_format_cap_count(ast_stream_get_formats(stream))));
-
- /* Check that stream types didn't change. */
- ast_assert(type[idx] == ast_stream_get_type(stream));
-
- /* Check that streams didn't get resurected. */
- ast_assert(state[idx] != AST_STREAM_STATE_REMOVED
- || ast_stream_get_state(stream) == AST_STREAM_STATE_REMOVED);
- }
-#endif
- }
-}
-
-/*!
- * \internal
- * \brief Allow a configured callback to alter the merged local topology.
- * \since 15.0.0
- *
- * \details
- * The callback can modify streams in the merged topology. The
- * callback can decline, add/remove/update formats, or rename
- * streams. Changing anything else on the streams is likely to not
- * end well.
- *
- * \param sdp_state
- * \param topology Merged topology that we intend to generate the offer SDP.
- *
- * \return Nothing
- */
-static void sdp_state_cb_offerer_modify_topology(const struct ast_sdp_state *sdp_state,
- struct ast_stream_topology *topology)
-{
- ast_sdp_offerer_modify_cb cb;
-
- cb = ast_sdp_options_get_offerer_modify_cb(sdp_state->options);
- if (cb) {
- void *context;
- const struct ast_stream_topology *neg_topology;/*!< Last negotiated topology */
-
- context = ast_sdp_options_get_state_context(sdp_state->options);
- neg_topology = sdp_state->negotiated_capabilities
- ? sdp_state->negotiated_capabilities->topology : NULL;
- cb(context, neg_topology, topology);
-
-#ifdef AST_DEVMODE
- {
- struct ast_stream *stream;
- int idx;
-
- /* Check that active streams have at least one format */
- for (idx = 0; idx < ast_stream_topology_get_count(topology); ++idx) {
- stream = ast_stream_topology_get_stream(topology, idx);
- ast_assert(ast_stream_get_state(stream) == AST_STREAM_STATE_REMOVED
- || (ast_stream_get_formats(stream)
- && ast_format_cap_count(ast_stream_get_formats(stream))));
- }
- }
-#endif
- }
-}
-
-/*!
- * \internal
- * \brief Allow a configured callback to configure the merged local topology.
- * \since 15.0.0
- *
- * \details
- * The callback can configure other parameters associated with each
- * active stream on the topology. The callback can call several SDP
- * API calls to configure the proposed capabilities of the streams
- * before we create the offer SDP. For example, the callback could
- * configure a stream specific connection address, T.38 parameters,
- * RTP instance, or UDPTL instance parameters.
- *
- * \param sdp_state
- * \param topology Merged topology that we intend to generate the offer SDP.
- *
- * \return Nothing
- */
-static void sdp_state_cb_offerer_config_topology(const struct ast_sdp_state *sdp_state,
- const struct ast_stream_topology *topology)
-{
- ast_sdp_offerer_config_cb cb;
-
- cb = ast_sdp_options_get_offerer_config_cb(sdp_state->options);
- if (cb) {
- void *context;
-
- context = ast_sdp_options_get_state_context(sdp_state->options);
- cb(context, topology);
- }
-}
-
-/*!
- * \internal
- * \brief Call any registered pre-apply topology callback.
- * \since 15.0.0
- *
- * \param sdp_state
- * \param topology
- *
- * \return Nothing
- */
-static void sdp_state_cb_preapply_topology(const struct ast_sdp_state *sdp_state,
- const struct ast_stream_topology *topology)
-{
- ast_sdp_preapply_cb cb;
-
- cb = ast_sdp_options_get_preapply_cb(sdp_state->options);
- if (cb) {
- void *context;
-
- context = ast_sdp_options_get_state_context(sdp_state->options);
- cb(context, topology);
- }
-}
-
-/*!
- * \internal
- * \brief Call any registered post-apply topology callback.
- * \since 15.0.0
- *
- * \param sdp_state
- * \param topology
- *
- * \return Nothing
- */
-static void sdp_state_cb_postapply_topology(const struct ast_sdp_state *sdp_state,
- const struct ast_stream_topology *topology)
-{
- ast_sdp_postapply_cb cb;
-
- cb = ast_sdp_options_get_postapply_cb(sdp_state->options);
- if (cb) {
- void *context;
-
- context = ast_sdp_options_get_state_context(sdp_state->options);
- cb(context, topology);
- }
-}
-
-static const struct sdp_state_capabilities *sdp_state_get_joint_capabilities(
- const struct ast_sdp_state *sdp_state)
-{
- ast_assert(sdp_state != NULL);
-
- if (sdp_state->negotiated_capabilities) {
- return sdp_state->negotiated_capabilities;
- }
-
- return sdp_state->proposed_capabilities;
-}
-
-static struct sdp_state_stream *sdp_state_get_stream(const struct ast_sdp_state *sdp_state, int stream_index)
-{
- if (stream_index >= AST_VECTOR_SIZE(&sdp_state->proposed_capabilities->streams)) {
- return NULL;
- }
-
- return AST_VECTOR_GET(&sdp_state->proposed_capabilities->streams, stream_index);
-}
-
-static struct sdp_state_stream *sdp_state_get_joint_stream(const struct ast_sdp_state *sdp_state, int stream_index)
-{
- const struct sdp_state_capabilities *capabilities;
-
- capabilities = sdp_state_get_joint_capabilities(sdp_state);
- if (AST_VECTOR_SIZE(&capabilities->streams) <= stream_index) {
- return NULL;
- }
-
- return AST_VECTOR_GET(&capabilities->streams, stream_index);
-}
-
-struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(
- const struct ast_sdp_state *sdp_state, int stream_index)
-{
- struct sdp_state_stream *stream_state;
-
- ast_assert(sdp_state != NULL);
- ast_assert(ast_stream_get_type(ast_stream_topology_get_stream(sdp_state->proposed_capabilities->topology,
- stream_index)) == AST_MEDIA_TYPE_AUDIO || ast_stream_get_type(ast_stream_topology_get_stream(
- sdp_state->proposed_capabilities->topology, stream_index)) == AST_MEDIA_TYPE_VIDEO);
-
- stream_state = sdp_state_get_stream(sdp_state, stream_index);
- if (!stream_state || !stream_state->rtp) {
- return NULL;
- }
-
- return stream_state->rtp->instance;
-}
-
-struct ast_udptl *ast_sdp_state_get_udptl_instance(
- const struct ast_sdp_state *sdp_state, int stream_index)
-{
- struct sdp_state_stream *stream_state;
-
- ast_assert(sdp_state != NULL);
- ast_assert(ast_stream_get_type(ast_stream_topology_get_stream(sdp_state->proposed_capabilities->topology,
- stream_index)) == AST_MEDIA_TYPE_IMAGE);
-
- stream_state = sdp_state_get_stream(sdp_state, stream_index);
- if (!stream_state || !stream_state->udptl) {
- return NULL;
- }
-
- return stream_state->udptl->instance;
-}
-
-const struct ast_sockaddr *ast_sdp_state_get_connection_address(const struct ast_sdp_state *sdp_state)
-{
- ast_assert(sdp_state != NULL);
-
- return &sdp_state->connection_address;
-}
-
-static int sdp_state_stream_get_connection_address(const struct ast_sdp_state *sdp_state,
- struct sdp_state_stream *stream_state, struct ast_sockaddr *address)
-{
- ast_assert(sdp_state != NULL);
- ast_assert(stream_state != NULL);
- ast_assert(address != NULL);
-
- /* If an explicit connection address has been provided for the stream return it */
- if (!ast_sockaddr_isnull(&stream_state->connection_address)) {
- ast_sockaddr_copy(address, &stream_state->connection_address);
- return 0;
- }
-
- switch (stream_state->type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- if (!stream_state->rtp->instance) {
- return -1;
- }
- ast_rtp_instance_get_local_address(stream_state->rtp->instance, address);
- break;
- case AST_MEDIA_TYPE_IMAGE:
- if (!stream_state->udptl->instance) {
- return -1;
- }
- ast_udptl_get_us(stream_state->udptl->instance, address);
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- return -1;
- }
-
- if (ast_sockaddr_isnull(address)) {
- /* No address is set on the stream state. */
- return -1;
- }
-
- /* If an explicit global connection address is set use it here for the IP part */
- if (!ast_sockaddr_isnull(&sdp_state->connection_address)) {
- int port = ast_sockaddr_port(address);
-
- ast_sockaddr_copy(address, &sdp_state->connection_address);
- ast_sockaddr_set_port(address, port);
- }
-
- return 0;
-}
-
-int ast_sdp_state_get_stream_connection_address(const struct ast_sdp_state *sdp_state,
- int stream_index, struct ast_sockaddr *address)
-{
- struct sdp_state_stream *stream_state;
-
- ast_assert(sdp_state != NULL);
- ast_assert(address != NULL);
-
- stream_state = sdp_state_get_stream(sdp_state, stream_index);
- if (!stream_state) {
- return -1;
- }
-
- return sdp_state_stream_get_connection_address(sdp_state, stream_state, address);
-}
-
-const struct ast_stream_topology *ast_sdp_state_get_joint_topology(
- const struct ast_sdp_state *sdp_state)
-{
- const struct sdp_state_capabilities *capabilities;
-
- capabilities = sdp_state_get_joint_capabilities(sdp_state);
- return capabilities->topology;
-}
-
-const struct ast_stream_topology *ast_sdp_state_get_local_topology(
- const struct ast_sdp_state *sdp_state)
-{
- ast_assert(sdp_state != NULL);
-
- return sdp_state->proposed_capabilities->topology;
-}
-
-const struct ast_sdp_options *ast_sdp_state_get_options(
- const struct ast_sdp_state *sdp_state)
-{
- ast_assert(sdp_state != NULL);
-
- return sdp_state->options;
-}
-
-static struct ast_stream *decline_stream(enum ast_media_type type, const char *name)
-{
- struct ast_stream *stream;
-
- if (!name) {
- name = ast_codec_media_type2str(type);
- }
- stream = ast_stream_alloc(name, type);
- if (!stream) {
- return NULL;
- }
- ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);
- return stream;
-}
-
-/*!
- * \brief Merge an update stream into a local stream.
- *
- * \param options SDP Options
- * \param update An updated stream
- *
- * \retval NULL An error occurred
- * \retval non-NULL The joint stream created
- */
-static struct ast_stream *merge_local_stream(const struct ast_sdp_options *options,
- const struct ast_stream *update)
-{
- struct ast_stream *joint_stream;
- struct ast_format_cap *joint_cap;
- struct ast_format_cap *allowed_cap;
- struct ast_format_cap *update_cap;
- enum ast_stream_state joint_state;
-
- joint_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- if (!joint_cap) {
- return NULL;
- }
-
- update_cap = ast_stream_get_formats(update);
- allowed_cap = ast_sdp_options_get_format_cap_type(options,
- ast_stream_get_type(update));
- if (allowed_cap && update_cap) {
- struct ast_str *allowed_buf = ast_str_alloca(128);
- struct ast_str *update_buf = ast_str_alloca(128);
- struct ast_str *joint_buf = ast_str_alloca(128);
-
- ast_format_cap_get_compatible(allowed_cap, update_cap, joint_cap);
- ast_debug(3,
- "Filtered update '%s' with allowed '%s' to get joint '%s'. Joint has %zu formats\n",
- ast_format_cap_get_names(update_cap, &update_buf),
- ast_format_cap_get_names(allowed_cap, &allowed_buf),
- ast_format_cap_get_names(joint_cap, &joint_buf),
- ast_format_cap_count(joint_cap));
- }
-
- /* Determine the joint stream state */
- joint_state = AST_STREAM_STATE_REMOVED;
- if (ast_stream_get_state(update) != AST_STREAM_STATE_REMOVED
- && ast_format_cap_count(joint_cap)) {
- joint_state = AST_STREAM_STATE_SENDRECV;
- }
-
- joint_stream = ast_stream_alloc(ast_stream_get_name(update),
- ast_stream_get_type(update));
- if (joint_stream) {
- ast_stream_set_state(joint_stream, joint_state);
- if (joint_state != AST_STREAM_STATE_REMOVED) {
- ast_stream_set_formats(joint_stream, joint_cap);
- }
- }
-
- ao2_ref(joint_cap, -1);
-
- return joint_stream;
-}
-
-/*!
- * \brief Merge a remote stream into a local stream.
- *
- * \param sdp_state
- * \param local Our local stream (NULL if creating new stream)
- * \param locally_held Nonzero if the local stream is held
- * \param remote A remote stream
- *
- * \retval NULL An error occurred
- * \retval non-NULL The joint stream created
- */
-static struct ast_stream *merge_remote_stream(const struct ast_sdp_state *sdp_state,
- const struct ast_stream *local, unsigned int locally_held,
- const struct ast_stream *remote)
-{
- struct ast_stream *joint_stream;
- struct ast_format_cap *joint_cap;
- struct ast_format_cap *local_cap;
- struct ast_format_cap *remote_cap;
- const char *joint_name;
- enum ast_stream_state joint_state;
- enum ast_stream_state remote_state;
-
- joint_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- if (!joint_cap) {
- return NULL;
- }
-
- remote_cap = ast_stream_get_formats(remote);
- if (local) {
- local_cap = ast_stream_get_formats(local);
- } else {
- local_cap = ast_sdp_options_get_format_cap_type(sdp_state->options,
- ast_stream_get_type(remote));
- }
- if (local_cap && remote_cap) {
- struct ast_str *local_buf = ast_str_alloca(128);
- struct ast_str *remote_buf = ast_str_alloca(128);
- struct ast_str *joint_buf = ast_str_alloca(128);
-
- ast_format_cap_get_compatible(local_cap, remote_cap, joint_cap);
- ast_debug(3,
- "Combined local '%s' with remote '%s' to get joint '%s'. Joint has %zu formats\n",
- ast_format_cap_get_names(local_cap, &local_buf),
- ast_format_cap_get_names(remote_cap, &remote_buf),
- ast_format_cap_get_names(joint_cap, &joint_buf),
- ast_format_cap_count(joint_cap));
- }
-
- /* Determine the joint stream state */
- remote_state = ast_stream_get_state(remote);
- joint_state = AST_STREAM_STATE_REMOVED;
- if ((!local || ast_stream_get_state(local) != AST_STREAM_STATE_REMOVED)
- && ast_format_cap_count(joint_cap)) {
- if (sdp_state->locally_held || locally_held) {
- switch (remote_state) {
- case AST_STREAM_STATE_REMOVED:
- break;
- case AST_STREAM_STATE_INACTIVE:
- joint_state = AST_STREAM_STATE_INACTIVE;
- break;
- case AST_STREAM_STATE_SENDRECV:
- joint_state = AST_STREAM_STATE_SENDONLY;
- break;
- case AST_STREAM_STATE_SENDONLY:
- joint_state = AST_STREAM_STATE_INACTIVE;
- break;
- case AST_STREAM_STATE_RECVONLY:
- joint_state = AST_STREAM_STATE_SENDONLY;
- break;
- }
- } else {
- switch (remote_state) {
- case AST_STREAM_STATE_REMOVED:
- break;
- case AST_STREAM_STATE_INACTIVE:
- joint_state = AST_STREAM_STATE_RECVONLY;
- break;
- case AST_STREAM_STATE_SENDRECV:
- joint_state = AST_STREAM_STATE_SENDRECV;
- break;
- case AST_STREAM_STATE_SENDONLY:
- joint_state = AST_STREAM_STATE_RECVONLY;
- break;
- case AST_STREAM_STATE_RECVONLY:
- joint_state = AST_STREAM_STATE_SENDRECV;
- break;
- }
- }
- }
-
- if (local) {
- joint_name = ast_stream_get_name(local);
- } else {
- joint_name = ast_codec_media_type2str(ast_stream_get_type(remote));
- }
- joint_stream = ast_stream_alloc(joint_name, ast_stream_get_type(remote));
- if (joint_stream) {
- ast_stream_set_state(joint_stream, joint_state);
- if (joint_state != AST_STREAM_STATE_REMOVED) {
- ast_stream_set_formats(joint_stream, joint_cap);
- }
- }
-
- ao2_ref(joint_cap, -1);
-
- return joint_stream;
-}
-
-/*!
- * \internal
- * \brief Determine if a merged topology should be rejected.
- * \since 15.0.0
- *
- * \param topology What topology to determine if we reject
- *
- * \retval 0 if not rejected.
- * \retval non-zero if rejected.
- */
-static int sdp_topology_is_rejected(struct ast_stream_topology *topology)
-{
- int idx;
- struct ast_stream *stream;
-
- for (idx = ast_stream_topology_get_count(topology); idx--;) {
- stream = ast_stream_topology_get_stream(topology, idx);
- if (ast_stream_get_state(stream) != AST_STREAM_STATE_REMOVED) {
- /* At least one stream is not declined */
- return 0;
- }
- }
-
- /* All streams are declined */
- return 1;
-}
-
-static void sdp_state_stream_copy_common(struct sdp_state_stream *dst, const struct sdp_state_stream *src)
-{
- ast_sockaddr_copy(&dst->connection_address,
- &src->connection_address);
- /* Explicitly does not copy the local or remote hold states. */
- dst->t38_local_params = src->t38_local_params;
-}
-
-static void sdp_state_stream_copy(struct sdp_state_stream *dst, const struct sdp_state_stream *src)
-{
- *dst = *src;
-
- switch (dst->type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- ao2_bump(dst->rtp);
- break;
- case AST_MEDIA_TYPE_IMAGE:
- ao2_bump(dst->udptl);
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- break;
- }
-}
-
-/*!
- * \internal
- * \brief Initialize an int vector and default the contents to the member index.
- * \since 15.0.0
- *
- * \param vect Vetctor to initialize and set to default values.
- * \param size Size of the vector to setup.
- *
- * \retval 0 on success.
- * \retval -1 on failure.
- */
-static int sdp_vect_idx_init(struct ast_vector_int *vect, size_t size)
-{
- int idx;
-
- if (AST_VECTOR_INIT(vect, size)) {
- return -1;
- }
- for (idx = 0; idx < size; ++idx) {
- AST_VECTOR_APPEND(vect, idx);
- }
- return 0;
-}
-
-/*!
- * \internal
- * \brief Compare stream types for sort order.
- * \since 15.0.0
- *
- * \param left Stream parameter on left
- * \param right Stream parameter on right
- *
- * \retval <0 left stream sorts first.
- * \retval =0 streams match.
- * \retval >0 right stream sorts first.
- */
-static int sdp_stream_cmp_by_type(const struct ast_stream *left, const struct ast_stream *right)
-{
- enum ast_media_type left_type = ast_stream_get_type(left);
- enum ast_media_type right_type = ast_stream_get_type(right);
-
- /* Treat audio and image as the same for T.38 support */
- if (left_type == AST_MEDIA_TYPE_IMAGE) {
- left_type = AST_MEDIA_TYPE_AUDIO;
- }
- if (right_type == AST_MEDIA_TYPE_IMAGE) {
- right_type = AST_MEDIA_TYPE_AUDIO;
- }
-
- return left_type - right_type;
-}
-
-/*!
- * \internal
- * \brief Compare stream names and types for sort order.
- * \since 15.0.0
- *
- * \param left Stream parameter on left
- * \param right Stream parameter on right
- *
- * \retval <0 left stream sorts first.
- * \retval =0 streams match.
- * \retval >0 right stream sorts first.
- */
-static int sdp_stream_cmp_by_name(const struct ast_stream *left, const struct ast_stream *right)
-{
- int cmp;
- const char *left_name;
-
- left_name = ast_stream_get_name(left);
- cmp = strcmp(left_name, ast_stream_get_name(right));
- if (!cmp) {
- cmp = sdp_stream_cmp_by_type(left, right);
- if (!cmp) {
- /* Are the stream names real or type names which aren't matchable? */
- if (ast_strlen_zero(left_name)
- || !strcmp(left_name, ast_codec_media_type2str(ast_stream_get_type(left)))
- || !strcmp(left_name, ast_codec_media_type2str(ast_stream_get_type(right)))) {
- /* The streams don't actually have real names */
- cmp = -1;
- }
- }
- }
- return cmp;
-}
-
-/*!
- * \internal
- * \brief Merge topology streams by the match function.
- * \since 15.0.0
- *
- * \param sdp_state
- * \param current_topology Topology to update with state.
- * \param update_topology Topology to merge into the current topology.
- * \param current_vect Stream index vector of remaining current_topology streams.
- * \param update_vect Stream index vector of remaining update_topology streams.
- * \param backfill_candidate Array of flags marking current_topology streams
- * that can be reused for a different stream.
- * \param match Stream comparison function to identify corresponding streams
- * between the current_topology and update_topology.
- * \param merged_topology Output topology of merged streams.
- * \param compact_streams TRUE if backfill and limit number of streams.
- *
- * \retval 0 on success.
- * \retval -1 on failure.
- */
-static int sdp_merge_streams_match(
- const struct ast_sdp_state *sdp_state,
- const struct ast_stream_topology *current_topology,
- const struct ast_stream_topology *update_topology,
- struct ast_vector_int *current_vect,
- struct ast_vector_int *update_vect,
- char backfill_candidate[],
- int (*match)(const struct ast_stream *left, const struct ast_stream *right),
- struct ast_stream_topology *merged_topology,
- int compact_streams)
-{
- struct ast_stream *current_stream;
- struct ast_stream *update_stream;
- int current_idx;
- int update_idx;
- int idx;
-
- for (current_idx = 0; current_idx < AST_VECTOR_SIZE(current_vect);) {
- idx = AST_VECTOR_GET(current_vect, current_idx);
- current_stream = ast_stream_topology_get_stream(current_topology, idx);
-
- for (update_idx = 0; update_idx < AST_VECTOR_SIZE(update_vect); ++update_idx) {
- idx = AST_VECTOR_GET(update_vect, update_idx);
- update_stream = ast_stream_topology_get_stream(update_topology, idx);
-
- if (match(current_stream, update_stream)) {
- continue;
- }
-
- if (!compact_streams
- || ast_stream_get_state(current_stream) != AST_STREAM_STATE_REMOVED
- || ast_stream_get_state(update_stream) != AST_STREAM_STATE_REMOVED) {
- struct ast_stream *merged_stream;
-
- merged_stream = merge_local_stream(sdp_state->options, update_stream);
- if (!merged_stream) {
- return -1;
- }
- idx = AST_VECTOR_GET(current_vect, current_idx);
- if (ast_stream_topology_set_stream(merged_topology, idx, merged_stream)) {
- ast_stream_free(merged_stream);
- return -1;
- }
-
- /*
- * The current_stream cannot be considered a backfill_candidate
- * anymore since it got updated.
- *
- * XXX It could be argued that if the declined status didn't
- * change because the merged_stream became declined then we
- * shouldn't remove the stream slot as a backfill_candidate
- * and we shouldn't update the merged_topology stream. If we
- * then backfilled the stream we would likely mess up the core
- * if it is matching streams by type since the core attempted
- * to update the stream with an incompatible stream. Any
- * backfilled streams could cause a stream type ordering
- * problem. However, we do need to reclaim declined stream
- * slots sometime.
- */
- backfill_candidate[idx] = 0;
- }
-
- AST_VECTOR_REMOVE_ORDERED(current_vect, current_idx);
- AST_VECTOR_REMOVE_ORDERED(update_vect, update_idx);
- goto matched_next;
- }
-
- ++current_idx;
-matched_next:;
- }
- return 0;
-}
-
-/*!
- * \internal
- * \brief Merge the current local topology with an updated topology.
- * \since 15.0.0
- *
- * \param sdp_state
- * \param current_topology Topology to update with state.
- * \param update_topology Topology to merge into the current topology.
- * \param compact_streams TRUE if backfill and limit number of streams.
- *
- * \retval merged topology on success.
- * \retval NULL on failure.
- */
-static struct ast_stream_topology *merge_local_topologies(
- const struct ast_sdp_state *sdp_state,
- const struct ast_stream_topology *current_topology,
- const struct ast_stream_topology *update_topology,
- int compact_streams)
-{
- struct ast_stream_topology *merged_topology;
- struct ast_stream *current_stream;
- struct ast_stream *update_stream;
- struct ast_stream *merged_stream;
- struct ast_vector_int current_vect;
- struct ast_vector_int update_vect;
- int current_idx = ast_stream_topology_get_count(current_topology);
- int update_idx;
- int idx;
- char backfill_candidate[current_idx];
-
- memset(backfill_candidate, 0, current_idx);
-
- if (compact_streams) {
- /* Limit matching consideration to the maximum allowed live streams. */
- idx = ast_sdp_options_get_max_streams(sdp_state->options);
- if (idx < current_idx) {
- current_idx = idx;
- }
- }
- if (sdp_vect_idx_init(&current_vect, current_idx)) {
- return NULL;
- }
-
- if (sdp_vect_idx_init(&update_vect, ast_stream_topology_get_count(update_topology))) {
- AST_VECTOR_FREE(&current_vect);
- return NULL;
- }
-
- merged_topology = ast_stream_topology_clone(current_topology);
- if (!merged_topology) {
- goto fail;
- }
-
- /*
- * Remove any unsupported current streams from match consideration
- * and mark potential backfill candidates.
- */
- for (current_idx = AST_VECTOR_SIZE(&current_vect); current_idx--;) {
- idx = AST_VECTOR_GET(&current_vect, current_idx);
- current_stream = ast_stream_topology_get_stream(current_topology, idx);
- if (ast_stream_get_state(current_stream) == AST_STREAM_STATE_REMOVED
- && compact_streams) {
- /* The declined stream is a potential backfill candidate */
- backfill_candidate[idx] = 1;
- }
- if (sdp_is_stream_type_supported(ast_stream_get_type(current_stream))) {
- continue;
- }
- /* Unsupported current streams should always be declined */
- ast_assert(ast_stream_get_state(current_stream) == AST_STREAM_STATE_REMOVED);
-
- AST_VECTOR_REMOVE_ORDERED(&current_vect, current_idx);
- }
-
- /* Remove any unsupported update streams from match consideration. */
- for (update_idx = AST_VECTOR_SIZE(&update_vect); update_idx--;) {
- idx = AST_VECTOR_GET(&update_vect, update_idx);
- update_stream = ast_stream_topology_get_stream(update_topology, idx);
- if (sdp_is_stream_type_supported(ast_stream_get_type(update_stream))) {
- continue;
- }
-
- AST_VECTOR_REMOVE_ORDERED(&update_vect, update_idx);
- }
-
- /* Match by stream name and type */
- if (sdp_merge_streams_match(sdp_state, current_topology, update_topology,
- &current_vect, &update_vect, backfill_candidate, sdp_stream_cmp_by_name,
- merged_topology, compact_streams)) {
- goto fail;
- }
-
- /* Match by stream type */
- if (sdp_merge_streams_match(sdp_state, current_topology, update_topology,
- &current_vect, &update_vect, backfill_candidate, sdp_stream_cmp_by_type,
- merged_topology, compact_streams)) {
- goto fail;
- }
-
- /* Decline unmatched current stream slots */
- for (current_idx = AST_VECTOR_SIZE(&current_vect); current_idx--;) {
- idx = AST_VECTOR_GET(&current_vect, current_idx);
- current_stream = ast_stream_topology_get_stream(current_topology, idx);
-
- if (ast_stream_get_state(current_stream) == AST_STREAM_STATE_REMOVED) {
- /* Stream is already declined. */
- continue;
- }
-
- merged_stream = decline_stream(ast_stream_get_type(current_stream),
- ast_stream_get_name(current_stream));
- if (!merged_stream) {
- goto fail;
- }
- if (ast_stream_topology_set_stream(merged_topology, idx, merged_stream)) {
- ast_stream_free(merged_stream);
- goto fail;
- }
- }
-
- /* Backfill new update stream slots into pre-existing declined current stream slots */
- while (AST_VECTOR_SIZE(&update_vect)) {
- idx = ast_stream_topology_get_count(current_topology);
- for (current_idx = 0; current_idx < idx; ++current_idx) {
- if (backfill_candidate[current_idx]) {
- break;
- }
- }
- if (idx <= current_idx) {
- /* No more backfill candidates remain. */
- break;
- }
- /* There should only be backfill stream slots when we are compact_streams */
- ast_assert(compact_streams);
-
- idx = AST_VECTOR_GET(&update_vect, 0);
- update_stream = ast_stream_topology_get_stream(update_topology, idx);
- AST_VECTOR_REMOVE_ORDERED(&update_vect, 0);
-
- if (ast_stream_get_state(update_stream) == AST_STREAM_STATE_REMOVED) {
- /* New stream is already declined so don't bother adding it. */
- continue;
- }
-
- merged_stream = merge_local_stream(sdp_state->options, update_stream);
- if (!merged_stream) {
- goto fail;
- }
- if (ast_stream_get_state(merged_stream) == AST_STREAM_STATE_REMOVED) {
- /* New stream not compatible so don't bother adding it. */
- ast_stream_free(merged_stream);
- continue;
- }
-
- /* Add the new stream into the backfill stream slot. */
- if (ast_stream_topology_set_stream(merged_topology, current_idx, merged_stream)) {
- ast_stream_free(merged_stream);
- goto fail;
- }
- backfill_candidate[current_idx] = 0;
- }
-
- /* Append any remaining new update stream slots that can fit. */
- while (AST_VECTOR_SIZE(&update_vect)
- && (!compact_streams
- || ast_stream_topology_get_count(merged_topology)
- < ast_sdp_options_get_max_streams(sdp_state->options))) {
- idx = AST_VECTOR_GET(&update_vect, 0);
- update_stream = ast_stream_topology_get_stream(update_topology, idx);
- AST_VECTOR_REMOVE_ORDERED(&update_vect, 0);
-
- if (ast_stream_get_state(update_stream) == AST_STREAM_STATE_REMOVED) {
- /* New stream is already declined so don't bother adding it. */
- continue;
- }
-
- merged_stream = merge_local_stream(sdp_state->options, update_stream);
- if (!merged_stream) {
- goto fail;
- }
- if (ast_stream_get_state(merged_stream) == AST_STREAM_STATE_REMOVED) {
- /* New stream not compatible so don't bother adding it. */
- ast_stream_free(merged_stream);
- continue;
- }
-
- /* Append the new update stream. */
- if (ast_stream_topology_append_stream(merged_topology, merged_stream) < 0) {
- ast_stream_free(merged_stream);
- goto fail;
- }
- }
-
- AST_VECTOR_FREE(&current_vect);
- AST_VECTOR_FREE(&update_vect);
- return merged_topology;
-
-fail:
- ast_stream_topology_free(merged_topology);
- AST_VECTOR_FREE(&current_vect);
- AST_VECTOR_FREE(&update_vect);
- return NULL;
-}
-
-/*!
- * \internal
- * \brief Remove declined streams appended beyond orig_topology.
- * \since 15.0.0
- *
- * \param sdp_state
- * \param orig_topology Negotiated or initial topology.
- * \param new_topology New proposed topology.
- *
- * \return Nothing
- */
-static void remove_appended_declined_streams(const struct ast_sdp_state *sdp_state,
- const struct ast_stream_topology *orig_topology,
- struct ast_stream_topology *new_topology)
-{
- struct ast_stream *stream;
- int orig_count;
- int idx;
-
- orig_count = ast_stream_topology_get_count(orig_topology);
- for (idx = ast_stream_topology_get_count(new_topology); orig_count < idx;) {
- --idx;
- stream = ast_stream_topology_get_stream(new_topology, idx);
- if (ast_stream_get_state(stream) != AST_STREAM_STATE_REMOVED) {
- continue;
- }
- ast_stream_topology_del_stream(new_topology, idx);
- }
-}
-
-/*!
- * \internal
- * \brief Setup a new state stream from a possibly existing state stream.
- * \since 15.0.0
- *
- * \param sdp_state
- * \param new_state_stream What state stream to setup
- * \param old_state_stream Source of previous state stream information.
- * May be NULL.
- * \param new_type Type of the new state stream.
- *
- * \retval 0 on success.
- * \retval -1 on failure.
- */
-static int setup_new_stream_capabilities(
- const struct ast_sdp_state *sdp_state,
- struct sdp_state_stream *new_state_stream,
- struct sdp_state_stream *old_state_stream,
- enum ast_media_type new_type)
-{
- if (old_state_stream) {
- /*
- * Copy everything potentially useful for a new stream state type
- * from the old stream of a possible different type.
- */
- sdp_state_stream_copy_common(new_state_stream, old_state_stream);
- /* We also need to preserve the locally_held state for the new stream. */
- new_state_stream->locally_held = old_state_stream->locally_held;
- }
- new_state_stream->type = new_type;
-
- switch (new_type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- new_state_stream->rtp = create_rtp(sdp_state->options, new_type);
- if (!new_state_stream->rtp) {
- return -1;
- }
- break;
- case AST_MEDIA_TYPE_IMAGE:
- new_state_stream->udptl = create_udptl(sdp_state->options);
- if (!new_state_stream->udptl) {
- return -1;
- }
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- break;
- }
- return 0;
-}
-
-/*!
- * \brief Merge existing stream capabilities and a new topology.
- *
- * \param sdp_state The state needing capabilities merged
- * \param new_topology The topology to merge with our proposed capabilities
- *
- * \details
- *
- * This is a bit complicated. The idea is that we already have some
- * capabilities set, and we've now been confronted with a new stream
- * topology from the system. We want to take what we had before and
- * merge them with the new topology from the system.
- *
- * According to the RFC, stream slots can change their types only if
- * they are carrying the same logical information or an offer is
- * reusing a declined slot or new stream slots are added to the end
- * of the list. Switching a stream from audio to T.38 makes sense
- * because the stream slot is carrying the same information just in a
- * different format.
- *
- * We can setup new streams offered by the system up to our
- * configured maximum stream slots. New stream slots requested over
- * the maximum are discarded.
- *
- * \retval NULL An error occurred
- * \retval non-NULL The merged capabilities
- */
-static struct sdp_state_capabilities *merge_local_capabilities(
- const struct ast_sdp_state *sdp_state,
- const struct ast_stream_topology *new_topology)
-{
- const struct sdp_state_capabilities *current = sdp_state->proposed_capabilities;
- struct sdp_state_capabilities *merged_capabilities;
- int idx;
-
- ast_assert(current != NULL);
-
- merged_capabilities = ast_calloc(1, sizeof(*merged_capabilities));
- if (!merged_capabilities) {
- return NULL;
- }
-
- merged_capabilities->topology = merge_local_topologies(sdp_state, current->topology,
- new_topology, 1);
- if (!merged_capabilities->topology) {
- goto fail;
- }
- sdp_state_cb_offerer_modify_topology(sdp_state, merged_capabilities->topology);
- remove_appended_declined_streams(sdp_state, current->topology,
- merged_capabilities->topology);
-
- if (AST_VECTOR_INIT(&merged_capabilities->streams,
- ast_stream_topology_get_count(merged_capabilities->topology))) {
- goto fail;
- }
-
- for (idx = 0; idx < ast_stream_topology_get_count(merged_capabilities->topology); ++idx) {
- struct sdp_state_stream *merged_state_stream;
- struct sdp_state_stream *current_state_stream;
- struct ast_stream *merged_stream;
- struct ast_stream *current_stream;
- enum ast_media_type merged_stream_type;
- enum ast_media_type current_stream_type;
-
- merged_state_stream = ast_calloc(1, sizeof(*merged_state_stream));
- if (!merged_state_stream) {
- goto fail;
- }
-
- merged_stream = ast_stream_topology_get_stream(merged_capabilities->topology, idx);
- merged_stream_type = ast_stream_get_type(merged_stream);
-
- if (idx < ast_stream_topology_get_count(current->topology)) {
- current_state_stream = AST_VECTOR_GET(&current->streams, idx);
- current_stream = ast_stream_topology_get_stream(current->topology, idx);
- current_stream_type = ast_stream_get_type(current_stream);
- } else {
- /* The merged topology is adding a stream */
- current_state_stream = NULL;
- current_stream = NULL;
- current_stream_type = AST_MEDIA_TYPE_UNKNOWN;
- }
-
- if (ast_stream_get_state(merged_stream) == AST_STREAM_STATE_REMOVED) {
- if (current_state_stream) {
- /* Copy everything potentially useful to a declined stream state. */
- sdp_state_stream_copy_common(merged_state_stream, current_state_stream);
- }
- merged_state_stream->type = merged_stream_type;
- } else if (!current_stream
- || ast_stream_get_state(current_stream) == AST_STREAM_STATE_REMOVED) {
- /* This is a new stream */
- if (setup_new_stream_capabilities(sdp_state, merged_state_stream,
- current_state_stream, merged_stream_type)) {
- sdp_state_stream_free(merged_state_stream);
- goto fail;
- }
- } else if (merged_stream_type == current_stream_type) {
- /* Stream type is not changing. */
- sdp_state_stream_copy(merged_state_stream, current_state_stream);
- } else {
- /*
- * Stream type is changing. Need to replace the stream.
- *
- * Unsupported streams should already be handled earlier because
- * they are always declined.
- */
- ast_assert(sdp_is_stream_type_supported(merged_stream_type));
-
- /*
- * XXX We might need to keep the old RTP instance if the new
- * stream type is also RTP. We would just be changing between
- * audio and video in that case. However we will create a new
- * RTP instance anyway since its purpose has to be changing.
- * Any RTP packets in flight from the old stream type might
- * cause mischief.
- */
- if (setup_new_stream_capabilities(sdp_state, merged_state_stream,
- current_state_stream, merged_stream_type)) {
- sdp_state_stream_free(merged_state_stream);
- goto fail;
- }
- }
-
- if (AST_VECTOR_APPEND(&merged_capabilities->streams, merged_state_stream)) {
- sdp_state_stream_free(merged_state_stream);
- goto fail;
- }
- }
-
- return merged_capabilities;
-
-fail:
- sdp_state_capabilities_free(merged_capabilities);
- return NULL;
-}
-
-static void merge_remote_stream_capabilities(
- const struct ast_sdp_state *sdp_state,
- struct sdp_state_stream *joint_state_stream,
- struct sdp_state_stream *local_state_stream,
- struct ast_stream *remote_stream)
-{
- struct ast_rtp_codecs *codecs;
-
- *joint_state_stream = *local_state_stream;
- /*
- * Need to explicitly set the type to the remote because we could
- * be changing the type between audio and video.
- */
- joint_state_stream->type = ast_stream_get_type(remote_stream);
-
- switch (joint_state_stream->type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- ao2_bump(joint_state_stream->rtp);
- codecs = ast_stream_get_data(remote_stream, AST_STREAM_DATA_RTP_CODECS);
- ast_assert(codecs != NULL);
- if (sdp_state->role == SDP_ROLE_ANSWERER) {
- /*
- * Setup rx payload type mapping to prefer the mapping
- * from the peer that the RFC says we SHOULD use.
- */
- ast_rtp_codecs_payloads_xover(codecs, codecs, NULL);
- }
- ast_rtp_codecs_payloads_copy(codecs,
- ast_rtp_instance_get_codecs(joint_state_stream->rtp->instance),
- joint_state_stream->rtp->instance);
- break;
- case AST_MEDIA_TYPE_IMAGE:
- joint_state_stream->udptl = ao2_bump(joint_state_stream->udptl);
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- break;
- }
-}
-
-static int create_remote_stream_capabilities(
- const struct ast_sdp_state *sdp_state,
- struct sdp_state_stream *joint_state_stream,
- struct sdp_state_stream *local_state_stream,
- struct ast_stream *remote_stream)
-{
- struct ast_rtp_codecs *codecs;
-
- /* We can only create streams if we are the answerer */
- ast_assert(sdp_state->role == SDP_ROLE_ANSWERER);
-
- if (local_state_stream) {
- /*
- * Copy everything potentially useful for a new stream state type
- * from the old stream of a possible different type.
- */
- sdp_state_stream_copy_common(joint_state_stream, local_state_stream);
- /* We also need to preserve the locally_held state for the new stream. */
- joint_state_stream->locally_held = local_state_stream->locally_held;
- }
- joint_state_stream->type = ast_stream_get_type(remote_stream);
-
- switch (joint_state_stream->type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- joint_state_stream->rtp = create_rtp(sdp_state->options, joint_state_stream->type);
- if (!joint_state_stream->rtp) {
- return -1;
- }
-
- /*
- * Setup rx payload type mapping to prefer the mapping
- * from the peer that the RFC says we SHOULD use.
- */
- codecs = ast_stream_get_data(remote_stream, AST_STREAM_DATA_RTP_CODECS);
- ast_assert(codecs != NULL);
- ast_rtp_codecs_payloads_xover(codecs, codecs, NULL);
- ast_rtp_codecs_payloads_copy(codecs,
- ast_rtp_instance_get_codecs(joint_state_stream->rtp->instance),
- joint_state_stream->rtp->instance);
- break;
- case AST_MEDIA_TYPE_IMAGE:
- joint_state_stream->udptl = create_udptl(sdp_state->options);
- if (!joint_state_stream->udptl) {
- return -1;
- }
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- break;
- }
- return 0;
-}
-
-/*!
- * \internal
- * \brief Create a joint topology from the remote topology.
- * \since 15.0.0
- *
- * \param sdp_state The state needing capabilities merged.
- * \param local Capabilities to merge the remote topology into.
- * \param remote_topology The topology to merge with our local capabilities.
- *
- * \retval joint topology on success.
- * \retval NULL on failure.
- */
-static struct ast_stream_topology *merge_remote_topology(
- const struct ast_sdp_state *sdp_state,
- const struct sdp_state_capabilities *local,
- const struct ast_stream_topology *remote_topology)
-{
- struct ast_stream_topology *joint_topology;
- int idx;
-
- joint_topology = ast_stream_topology_alloc();
- if (!joint_topology) {
- return NULL;
- }
-
- for (idx = 0; idx < ast_stream_topology_get_count(remote_topology); ++idx) {
- enum ast_media_type local_stream_type;
- enum ast_media_type remote_stream_type;
- struct ast_stream *remote_stream;
- struct ast_stream *local_stream;
- struct ast_stream *joint_stream;
- struct sdp_state_stream *local_state_stream;
-
- remote_stream = ast_stream_topology_get_stream(remote_topology, idx);
- remote_stream_type = ast_stream_get_type(remote_stream);
-
- if (idx < ast_stream_topology_get_count(local->topology)) {
- local_state_stream = AST_VECTOR_GET(&local->streams, idx);
- local_stream = ast_stream_topology_get_stream(local->topology, idx);
- local_stream_type = ast_stream_get_type(local_stream);
- } else {
- /* The remote is adding a stream slot */
- local_state_stream = NULL;
- local_stream = NULL;
- local_stream_type = AST_MEDIA_TYPE_UNKNOWN;
-
- if (sdp_state->role != SDP_ROLE_ANSWERER) {
- /* Remote cannot add a new stream slot in an answer SDP */
- ast_debug(1,
- "Bad. Ignoring new %s stream slot remote answer SDP trying to add.\n",
- ast_codec_media_type2str(remote_stream_type));
- continue;
- }
- }
-
- if (local_stream
- && ast_stream_get_state(local_stream) != AST_STREAM_STATE_REMOVED) {
- if (remote_stream_type == local_stream_type) {
- /* Stream type is not changing. */
- joint_stream = merge_remote_stream(sdp_state, local_stream,
- local_state_stream->locally_held, remote_stream);
- } else if (sdp_state->role == SDP_ROLE_ANSWERER) {
- /* Stream type is changing. */
- joint_stream = merge_remote_stream(sdp_state, NULL,
- local_state_stream->locally_held, remote_stream);
- } else {
- /*
- * Remote cannot change the stream type we offered.
- * Mark as declined.
- */
- ast_debug(1,
- "Bad. Remote answer SDP trying to change the stream type from %s to %s.\n",
- ast_codec_media_type2str(local_stream_type),
- ast_codec_media_type2str(remote_stream_type));
- joint_stream = decline_stream(local_stream_type,
- ast_stream_get_name(local_stream));
- }
- } else {
- /* Local stream is either dead/declined or nonexistent. */
- if (sdp_state->role == SDP_ROLE_ANSWERER) {
- if (sdp_is_stream_type_supported(remote_stream_type)
- && ast_stream_get_state(remote_stream) != AST_STREAM_STATE_REMOVED
- && idx < ast_sdp_options_get_max_streams(sdp_state->options)) {
- /* Try to create the new stream */
- joint_stream = merge_remote_stream(sdp_state, NULL,
- local_state_stream ? local_state_stream->locally_held : 0,
- remote_stream);
- } else {
- const char *stream_name;
-
- /* Decline the remote stream. */
- if (local_stream
- && local_stream_type == remote_stream_type) {
- /* Preserve the previous stream name */
- stream_name = ast_stream_get_name(local_stream);
- } else {
- stream_name = NULL;
- }
- joint_stream = decline_stream(remote_stream_type, stream_name);
- }
- } else {
- /* Decline the stream. */
- if (DEBUG_ATLEAST(1)
- && ast_stream_get_state(remote_stream) != AST_STREAM_STATE_REMOVED) {
- /*
- * Remote cannot request a new stream in place of a declined
- * stream in an answer SDP.
- */
- ast_log(LOG_DEBUG,
- "Bad. Remote answer SDP trying to use a declined stream slot for %s.\n",
- ast_codec_media_type2str(remote_stream_type));
- }
- joint_stream = decline_stream(local_stream_type,
- ast_stream_get_name(local_stream));
- }
- }
-
- if (!joint_stream) {
- goto fail;
- }
- if (ast_stream_topology_append_stream(joint_topology, joint_stream) < 0) {
- ast_stream_free(joint_stream);
- goto fail;
- }
- }
-
- return joint_topology;
-
-fail:
- ast_stream_topology_free(joint_topology);
- return NULL;
-}
-
-/*!
- * \brief Merge our stream capabilities and a remote topology into joint capabilities.
- *
- * \param sdp_state The state needing capabilities merged
- * \param remote_topology The topology to merge with our proposed capabilities
- *
- * \details
- * This is a bit complicated. The idea is that we already have some
- * capabilities set, and we've now been confronted with a stream
- * topology from the remote end. We want to take what's been
- * presented to us and merge those new capabilities with our own.
- *
- * According to the RFC, stream slots can change their types only if
- * they are carrying the same logical information or an offer is
- * reusing a declined slot or new stream slots are added to the end
- * of the list. Switching a stream from audio to T.38 makes sense
- * because the stream slot is carrying the same information just in a
- * different format.
- *
- * When we are the answerer we can setup new streams offered by the
- * remote up to our configured maximum stream slots. New stream
- * slots offered over the maximum are unconditionally declined.
- *
- * \retval NULL An error occurred
- * \retval non-NULL The merged capabilities
- */
-static struct sdp_state_capabilities *merge_remote_capabilities(
- const struct ast_sdp_state *sdp_state,
- const struct ast_stream_topology *remote_topology)
-{
- const struct sdp_state_capabilities *local = sdp_state->proposed_capabilities;
- struct sdp_state_capabilities *joint_capabilities;
- int idx;
-
- ast_assert(local != NULL);
-
- joint_capabilities = ast_calloc(1, sizeof(*joint_capabilities));
- if (!joint_capabilities) {
- return NULL;
- }
-
- joint_capabilities->topology = merge_remote_topology(sdp_state, local, remote_topology);
- if (!joint_capabilities->topology) {
- goto fail;
- }
-
- if (sdp_state->role == SDP_ROLE_ANSWERER) {
- sdp_state_cb_answerer_modify_topology(sdp_state, joint_capabilities->topology);
- }
- idx = ast_stream_topology_get_count(joint_capabilities->topology);
- if (AST_VECTOR_INIT(&joint_capabilities->streams, idx)) {
- goto fail;
- }
-
- for (idx = 0; idx < ast_stream_topology_get_count(remote_topology); ++idx) {
- enum ast_media_type local_stream_type;
- enum ast_media_type remote_stream_type;
- struct ast_stream *remote_stream;
- struct ast_stream *local_stream;
- struct ast_stream *joint_stream;
- struct sdp_state_stream *local_state_stream;
- struct sdp_state_stream *joint_state_stream;
-
- joint_state_stream = ast_calloc(1, sizeof(*joint_state_stream));
- if (!joint_state_stream) {
- goto fail;
- }
-
- remote_stream = ast_stream_topology_get_stream(remote_topology, idx);
- remote_stream_type = ast_stream_get_type(remote_stream);
-
- if (idx < ast_stream_topology_get_count(local->topology)) {
- local_state_stream = AST_VECTOR_GET(&local->streams, idx);
- local_stream = ast_stream_topology_get_stream(local->topology, idx);
- local_stream_type = ast_stream_get_type(local_stream);
- } else {
- /* The remote is adding a stream slot */
- local_state_stream = NULL;
- local_stream = NULL;
- local_stream_type = AST_MEDIA_TYPE_UNKNOWN;
-
- if (sdp_state->role != SDP_ROLE_ANSWERER) {
- /* Remote cannot add a new stream slot in an answer SDP */
- sdp_state_stream_free(joint_state_stream);
- break;
- }
- }
-
- joint_stream = ast_stream_topology_get_stream(joint_capabilities->topology,
- idx);
-
- if (local_stream
- && ast_stream_get_state(local_stream) != AST_STREAM_STATE_REMOVED) {
- if (ast_stream_get_state(joint_stream) == AST_STREAM_STATE_REMOVED) {
- /* Copy everything potentially useful to a declined stream state. */
- sdp_state_stream_copy_common(joint_state_stream, local_state_stream);
-
- joint_state_stream->type = ast_stream_get_type(joint_stream);
- } else if (remote_stream_type == local_stream_type) {
- /* Stream type is not changing. */
- merge_remote_stream_capabilities(sdp_state, joint_state_stream,
- local_state_stream, remote_stream);
- ast_assert(joint_state_stream->type == ast_stream_get_type(joint_stream));
- } else {
- /*
- * Stream type is changing. Need to replace the stream.
- *
- * XXX We might need to keep the old RTP instance if the new
- * stream type is also RTP. We would just be changing between
- * audio and video in that case. However we will create a new
- * RTP instance anyway since its purpose has to be changing.
- * Any RTP packets in flight from the old stream type might
- * cause mischief.
- */
- if (create_remote_stream_capabilities(sdp_state, joint_state_stream,
- local_state_stream, remote_stream)) {
- sdp_state_stream_free(joint_state_stream);
- goto fail;
- }
- ast_assert(joint_state_stream->type == ast_stream_get_type(joint_stream));
- }
- } else {
- /* Local stream is either dead/declined or nonexistent. */
- if (sdp_state->role == SDP_ROLE_ANSWERER) {
- if (ast_stream_get_state(joint_stream) == AST_STREAM_STATE_REMOVED) {
- if (local_state_stream) {
- /* Copy everything potentially useful to a declined stream state. */
- sdp_state_stream_copy_common(joint_state_stream, local_state_stream);
- }
- joint_state_stream->type = ast_stream_get_type(joint_stream);
- } else {
- /* Try to create the new stream */
- if (create_remote_stream_capabilities(sdp_state, joint_state_stream,
- local_state_stream, remote_stream)) {
- sdp_state_stream_free(joint_state_stream);
- goto fail;
- }
- ast_assert(joint_state_stream->type == ast_stream_get_type(joint_stream));
- }
- } else {
- /* Decline the stream. */
- ast_assert(ast_stream_get_state(joint_stream) == AST_STREAM_STATE_REMOVED);
- if (local_state_stream) {
- /* Copy everything potentially useful to a declined stream state. */
- sdp_state_stream_copy_common(joint_state_stream, local_state_stream);
- }
- joint_state_stream->type = ast_stream_get_type(joint_stream);
- }
- }
-
- /* Determine if the remote placed the stream on hold. */
- joint_state_stream->remotely_held = 0;
- if (ast_stream_get_state(joint_stream) != AST_STREAM_STATE_REMOVED) {
- enum ast_stream_state remote_state;
-
- remote_state = ast_stream_get_state(remote_stream);
- switch (remote_state) {
- case AST_STREAM_STATE_INACTIVE:
- case AST_STREAM_STATE_SENDONLY:
- joint_state_stream->remotely_held = 1;
- break;
- default:
- break;
- }
- }
-
- if (AST_VECTOR_APPEND(&joint_capabilities->streams, joint_state_stream)) {
- sdp_state_stream_free(joint_state_stream);
- goto fail;
- }
- }
-
- return joint_capabilities;
-
-fail:
- sdp_state_capabilities_free(joint_capabilities);
- return NULL;
-}
-
-/*!
- * \brief Apply remote SDP's ICE information to our RTP session
- *
- * \param state The SDP state on which negotiation has taken place
- * \param options The SDP options we support
- * \param remote_sdp The SDP we most recently received
- * \param remote_m_line The stream on which we are examining ICE candidates
- */
-static void update_ice(const struct ast_sdp_state *state, struct ast_rtp_instance *rtp, const struct ast_sdp_options *options,
- const struct ast_sdp *remote_sdp, const struct ast_sdp_m_line *remote_m_line)
-{
- struct ast_rtp_engine_ice *ice;
- const struct ast_sdp_a_line *attr;
- const struct ast_sdp_a_line *attr_rtcp_mux;
- unsigned int attr_i;
-
- /* If ICE support is not enabled or available exit early */
- if (ast_sdp_options_get_ice(options) != AST_SDP_ICE_ENABLED_STANDARD || !(ice = ast_rtp_instance_get_ice(rtp))) {
- return;
- }
-
- attr = ast_sdp_m_find_attribute(remote_m_line, "ice-ufrag", -1);
- if (!attr) {
- attr = ast_sdp_find_attribute(remote_sdp, "ice-ufrag", -1);
- }
- if (attr) {
- ice->set_authentication(rtp, attr->value, NULL);
- } else {
- return;
- }
-
- attr = ast_sdp_m_find_attribute(remote_m_line, "ice-pwd", -1);
- if (!attr) {
- attr = ast_sdp_find_attribute(remote_sdp, "ice-pwd", -1);
- }
- if (attr) {
- ice->set_authentication(rtp, NULL, attr->value);
- } else {
- return;
- }
-
- if (ast_sdp_find_attribute(remote_sdp, "ice-lite", -1)) {
- ice->ice_lite(rtp);
- }
-
- attr_rtcp_mux = ast_sdp_m_find_attribute(remote_m_line, "rtcp-mux", -1);
-
- /* Find all of the candidates */
- for (attr_i = 0; attr_i < ast_sdp_m_get_a_count(remote_m_line); ++attr_i) {
- char foundation[33];
- char transport[32];
- char address[INET6_ADDRSTRLEN + 1];
- char cand_type[6];
- char relay_address[INET6_ADDRSTRLEN + 1] = "";
- unsigned int port;
- unsigned int relay_port = 0;
- struct ast_rtp_engine_ice_candidate candidate = { 0, };
-
- attr = ast_sdp_m_get_a(remote_m_line, attr_i);
-
- /* If this is not a candidate line skip it */
- if (strcmp(attr->name, "candidate")) {
- continue;
- }
-
- if (sscanf(attr->value, "%32s %30u %31s %30u %46s %30u typ %5s %*s %23s %*s %30u",
- foundation, &candidate.id, transport, (unsigned *)&candidate.priority, address,
- &port, cand_type, relay_address, &relay_port) < 7) {
- /* Candidate did not parse properly */
- continue;
- }
-
- if (candidate.id > 1
- && attr_rtcp_mux
- && ast_sdp_options_get_rtcp_mux(options)) {
- /* Remote side may have offered RTP and RTCP candidates. However, if we're using RTCP MUX,
- * then we should ignore RTCP candidates.
- */
- continue;
- }
-
- candidate.foundation = foundation;
- candidate.transport = transport;
-
- ast_sockaddr_parse(&candidate.address, address, PARSE_PORT_FORBID);
- ast_sockaddr_set_port(&candidate.address, port);
-
- if (!strcasecmp(cand_type, "host")) {
- candidate.type = AST_RTP_ICE_CANDIDATE_TYPE_HOST;
- } else if (!strcasecmp(cand_type, "srflx")) {
- candidate.type = AST_RTP_ICE_CANDIDATE_TYPE_SRFLX;
- } else if (!strcasecmp(cand_type, "relay")) {
- candidate.type = AST_RTP_ICE_CANDIDATE_TYPE_RELAYED;
- } else {
- continue;
- }
-
- if (!ast_strlen_zero(relay_address)) {
- ast_sockaddr_parse(&candidate.relay_address, relay_address, PARSE_PORT_FORBID);
- }
-
- if (relay_port) {
- ast_sockaddr_set_port(&candidate.relay_address, relay_port);
- }
-
- ice->add_remote_candidate(rtp, &candidate);
- }
-
- if (state->role == SDP_ROLE_OFFERER) {
- ice->set_role(rtp, AST_RTP_ICE_ROLE_CONTROLLING);
- } else {
- ice->set_role(rtp, AST_RTP_ICE_ROLE_CONTROLLED);
- }
-
- ice->start(rtp);
-}
-
-/*!
- * \brief Update RTP instances based on merged SDPs
- *
- * RTP instances, when first allocated, cannot make assumptions about what the other
- * side supports and thus has to go with some default behaviors. This function gets
- * called after we know both what we support and what the remote endpoint supports.
- * This way, we can update the RTP instance to reflect what is supported by both
- * sides.
- *
- * \param state The SDP state in which SDPs have been negotiated
- * \param rtp The RTP wrapper that is being updated
- * \param options Our locally-supported SDP options
- * \param remote_sdp The SDP we most recently received
- * \param remote_m_line The remote SDP stream that corresponds to the RTP instance we are modifying
- */
-static void update_rtp_after_merge(const struct ast_sdp_state *state,
- struct sdp_state_rtp *rtp,
- const struct ast_sdp_options *options,
- const struct ast_sdp *remote_sdp,
- const struct ast_sdp_m_line *remote_m_line)
-{
- struct ast_sdp_c_line *c_line;
- struct ast_sockaddr *addrs;
-
- c_line = remote_m_line->c_line;
- if (!c_line) {
- c_line = remote_sdp->c_line;
- }
- /*
- * There must be a c= line somewhere but that would be an error by
- * the far end that should have been caught by a validation check
- * before we processed the SDP.
- */
- ast_assert(c_line != NULL);
-
- if (ast_sockaddr_resolve(&addrs, c_line->address, PARSE_PORT_FORBID, AST_AF_UNSPEC) > 0) {
- /* Apply connection information to the RTP instance */
- ast_sockaddr_set_port(addrs, remote_m_line->port);
- ast_rtp_instance_set_remote_address(rtp->instance, addrs);
- ast_free(addrs);
- }
-
- if (ast_sdp_options_get_rtcp_mux(options)
- && ast_sdp_m_find_attribute(remote_m_line, "rtcp-mux", -1)) {
- ast_rtp_instance_set_prop(rtp->instance, AST_RTP_PROPERTY_RTCP,
- AST_RTP_INSTANCE_RTCP_MUX);
- } else {
- ast_rtp_instance_set_prop(rtp->instance, AST_RTP_PROPERTY_RTCP,
- AST_RTP_INSTANCE_RTCP_STANDARD);
- }
-
- update_ice(state, rtp->instance, options, remote_sdp, remote_m_line);
-}
-
-/*!
- * \brief Update UDPTL instances based on merged SDPs
- *
- * UDPTL instances, when first allocated, cannot make assumptions about what the other
- * side supports and thus has to go with some default behaviors. This function gets
- * called after we know both what we support and what the remote endpoint supports.
- * This way, we can update the UDPTL instance to reflect what is supported by both
- * sides.
- *
- * \param state The SDP state in which SDPs have been negotiated
- * \param udptl The UDPTL instance that is being updated
- * \param options Our locally-supported SDP options
- * \param remote_sdp The SDP we most recently received
- * \param remote_m_line The remote SDP stream that corresponds to the RTP instance we are modifying
- */
-static void update_udptl_after_merge(const struct ast_sdp_state *state, struct sdp_state_udptl *udptl,
- const struct ast_sdp_options *options,
- const struct ast_sdp *remote_sdp,
- const struct ast_sdp_m_line *remote_m_line)
-{
- struct ast_sdp_a_line *a_line;
- struct ast_sdp_c_line *c_line;
- unsigned int fax_max_datagram;
- struct ast_sockaddr *addrs;
-
- a_line = ast_sdp_m_find_attribute(remote_m_line, "t38faxmaxdatagram", -1);
- if (!a_line) {
- a_line = ast_sdp_m_find_attribute(remote_m_line, "t38maxdatagram", -1);
- }
- if (a_line && !ast_sdp_options_get_udptl_far_max_datagram(options) &&
- (sscanf(a_line->value, "%30u", &fax_max_datagram) == 1)) {
- ast_udptl_set_far_max_datagram(udptl->instance, fax_max_datagram);
- }
-
- a_line = ast_sdp_m_find_attribute(remote_m_line, "t38faxudpec", -1);
- if (a_line) {
- if (!strcasecmp(a_line->value, "t38UDPRedundancy")) {
- ast_udptl_set_error_correction_scheme(udptl->instance, UDPTL_ERROR_CORRECTION_REDUNDANCY);
- } else if (!strcasecmp(a_line->value, "t38UDPFEC")) {
- ast_udptl_set_error_correction_scheme(udptl->instance, UDPTL_ERROR_CORRECTION_FEC);
- } else {
- ast_udptl_set_error_correction_scheme(udptl->instance, UDPTL_ERROR_CORRECTION_NONE);
- }
- }
-
- c_line = remote_m_line->c_line;
- if (!c_line) {
- c_line = remote_sdp->c_line;
- }
- /*
- * There must be a c= line somewhere but that would be an error by
- * the far end that should have been caught by a validation check
- * before we processed the SDP.
- */
- ast_assert(c_line != NULL);
-
- if (ast_sockaddr_resolve(&addrs, c_line->address, PARSE_PORT_FORBID, AST_AF_UNSPEC) > 0) {
- /* Apply connection information to the UDPTL instance */
- ast_sockaddr_set_port(addrs, remote_m_line->port);
- ast_udptl_set_peer(udptl->instance, addrs);
- ast_free(addrs);
- }
-}
-
-static void sdp_apply_negotiated_state(struct ast_sdp_state *sdp_state)
-{
- struct sdp_state_capabilities *capabilities = sdp_state->negotiated_capabilities;
- int idx;
-
- if (!capabilities) {
- /* Nothing to apply */
- return;
- }
-
- sdp_state_cb_preapply_topology(sdp_state, capabilities->topology);
- for (idx = 0; idx < AST_VECTOR_SIZE(&capabilities->streams); ++idx) {
- struct sdp_state_stream *state_stream;
- struct ast_stream *stream;
-
- stream = ast_stream_topology_get_stream(capabilities->topology, idx);
- if (ast_stream_get_state(stream) == AST_STREAM_STATE_REMOVED) {
- /* Stream is declined */
- continue;
- }
-
- state_stream = AST_VECTOR_GET(&capabilities->streams, idx);
- switch (ast_stream_get_type(stream)) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- update_rtp_after_merge(sdp_state, state_stream->rtp, sdp_state->options,
- sdp_state->remote_sdp, ast_sdp_get_m(sdp_state->remote_sdp, idx));
- break;
- case AST_MEDIA_TYPE_IMAGE:
- update_udptl_after_merge(sdp_state, state_stream->udptl, sdp_state->options,
- sdp_state->remote_sdp, ast_sdp_get_m(sdp_state->remote_sdp, idx));
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- /* All unsupported streams are declined */
- ast_assert(0);
- break;
- }
- }
- sdp_state_cb_postapply_topology(sdp_state, capabilities->topology);
-}
-
-static void set_negotiated_capabilities(struct ast_sdp_state *sdp_state,
- struct sdp_state_capabilities *new_capabilities)
-{
- struct sdp_state_capabilities *old_capabilities = sdp_state->negotiated_capabilities;
-
- sdp_state->negotiated_capabilities = new_capabilities;
- sdp_state_capabilities_free(old_capabilities);
-}
-
-static void set_proposed_capabilities(struct ast_sdp_state *sdp_state,
- struct sdp_state_capabilities *new_capabilities)
-{
- struct sdp_state_capabilities *old_capabilities = sdp_state->proposed_capabilities;
-
- sdp_state->proposed_capabilities = new_capabilities;
- sdp_state_capabilities_free(old_capabilities);
-}
-
-/*!
- * \internal
- * \brief Copy the new capabilities into the proposed capabilities.
- * \since 15.0.0
- *
- * \param sdp_state The current SDP state
- * \param new_capabilities Capabilities to copy
- *
- * \retval 0 on success.
- * \retval -1 on failure.
- */
-static int update_proposed_capabilities(struct ast_sdp_state *sdp_state,
- struct sdp_state_capabilities *new_capabilities)
-{
- struct sdp_state_capabilities *proposed_capabilities;
- int idx;
-
- proposed_capabilities = ast_calloc(1, sizeof(*proposed_capabilities));
- if (!proposed_capabilities) {
- return -1;
- }
-
- proposed_capabilities->topology = ast_stream_topology_clone(new_capabilities->topology);
- if (!proposed_capabilities->topology) {
- goto fail;
- }
-
- if (AST_VECTOR_INIT(&proposed_capabilities->streams,
- AST_VECTOR_SIZE(&new_capabilities->streams))) {
- goto fail;
- }
-
- for (idx = 0; idx < AST_VECTOR_SIZE(&new_capabilities->streams); ++idx) {
- struct sdp_state_stream *proposed_state_stream;
- struct sdp_state_stream *new_state_stream;
-
- proposed_state_stream = ast_calloc(1, sizeof(*proposed_state_stream));
- if (!proposed_state_stream) {
- goto fail;
- }
-
- new_state_stream = AST_VECTOR_GET(&new_capabilities->streams, idx);
- *proposed_state_stream = *new_state_stream;
-
- switch (proposed_state_stream->type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- ao2_bump(proposed_state_stream->rtp);
- break;
- case AST_MEDIA_TYPE_IMAGE:
- ao2_bump(proposed_state_stream->udptl);
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- break;
- }
-
- /* This is explicitly never set on the proposed capabilities struct */
- proposed_state_stream->remotely_held = 0;
-
- if (AST_VECTOR_APPEND(&proposed_capabilities->streams, proposed_state_stream)) {
- sdp_state_stream_free(proposed_state_stream);
- goto fail;
- }
- }
-
- set_proposed_capabilities(sdp_state, proposed_capabilities);
- return 0;
-
-fail:
- sdp_state_capabilities_free(proposed_capabilities);
- return -1;
-}
-
-static struct ast_sdp *sdp_create_from_state(const struct ast_sdp_state *sdp_state,
- const struct sdp_state_capabilities *capabilities);
-
-/*!
- * \brief Merge SDPs into a joint SDP.
- *
- * This function is used to take a remote SDP and merge it with our local
- * capabilities to produce a new local SDP. After creating the new local SDP,
- * it then iterates through media instances and updates them as necessary. For
- * instance, if a specific RTP feature is supported by both us and the far end,
- * then we can ensure that the feature is enabled.
- *
- * \param sdp_state The current SDP state
- *
- * \retval 0 Success
- * \retval -1 Failure
- * Use ast_sdp_state_is_offer_rejected() to see if the offer SDP was rejected.
- */
-static int merge_sdps(struct ast_sdp_state *sdp_state, const struct ast_sdp *remote_sdp)
-{
- struct sdp_state_capabilities *joint_capabilities;
- struct ast_stream_topology *remote_capabilities;
-
- remote_capabilities = ast_get_topology_from_sdp(remote_sdp,
- ast_sdp_options_get_g726_non_standard(sdp_state->options));
- if (!remote_capabilities) {
- return -1;
- }
-
- joint_capabilities = merge_remote_capabilities(sdp_state, remote_capabilities);
- ast_stream_topology_free(remote_capabilities);
- if (!joint_capabilities) {
- return -1;
- }
- if (sdp_state->role == SDP_ROLE_ANSWERER) {
- sdp_state->remote_offer_rejected =
- sdp_topology_is_rejected(joint_capabilities->topology) ? 1 : 0;
- if (sdp_state->remote_offer_rejected) {
- sdp_state_capabilities_free(joint_capabilities);
- return -1;
- }
- }
- set_negotiated_capabilities(sdp_state, joint_capabilities);
-
- ao2_cleanup(sdp_state->remote_sdp);
- sdp_state->remote_sdp = ao2_bump((struct ast_sdp *) remote_sdp);
-
- sdp_apply_negotiated_state(sdp_state);
-
- return 0;
-}
-
-const struct ast_sdp *ast_sdp_state_get_local_sdp(struct ast_sdp_state *sdp_state)
-{
- ast_assert(sdp_state != NULL);
-
- switch (sdp_state->role) {
- case SDP_ROLE_NOT_SET:
- ast_assert(sdp_state->local_sdp == NULL);
- sdp_state->role = SDP_ROLE_OFFERER;
-
- if (sdp_state->pending_topology_update) {
- struct sdp_state_capabilities *capabilities;
-
- /* We have a topology update to perform before generating the offer */
- capabilities = merge_local_capabilities(sdp_state,
- sdp_state->pending_topology_update);
- if (!capabilities) {
- break;
- }
- ast_stream_topology_free(sdp_state->pending_topology_update);
- sdp_state->pending_topology_update = NULL;
- set_proposed_capabilities(sdp_state, capabilities);
- }
-
- /*
- * Allow the system to configure the topology streams
- * before we create the offer SDP.
- */
- sdp_state_cb_offerer_config_topology(sdp_state,
- sdp_state->proposed_capabilities->topology);
-
- sdp_state->local_sdp = sdp_create_from_state(sdp_state, sdp_state->proposed_capabilities);
- break;
- case SDP_ROLE_OFFERER:
- break;
- case SDP_ROLE_ANSWERER:
- if (!sdp_state->local_sdp
- && sdp_state->negotiated_capabilities
- && !sdp_state->remote_offer_rejected) {
- sdp_state->local_sdp = sdp_create_from_state(sdp_state, sdp_state->negotiated_capabilities);
- }
- break;
- }
-
- return sdp_state->local_sdp;
-}
-
-const void *ast_sdp_state_get_local_sdp_impl(struct ast_sdp_state *sdp_state)
-{
- const struct ast_sdp *sdp = ast_sdp_state_get_local_sdp(sdp_state);
-
- if (!sdp) {
- return NULL;
- }
-
- return ast_sdp_translator_from_sdp(sdp_state->translator, sdp);
-}
-
-int ast_sdp_state_set_remote_sdp(struct ast_sdp_state *sdp_state, const struct ast_sdp *sdp)
-{
- ast_assert(sdp_state != NULL);
-
- if (sdp_state->role == SDP_ROLE_NOT_SET) {
- sdp_state->role = SDP_ROLE_ANSWERER;
- }
-
- return merge_sdps(sdp_state, sdp);
-}
-
-int ast_sdp_state_set_remote_sdp_from_impl(struct ast_sdp_state *sdp_state, const void *remote)
-{
- struct ast_sdp *sdp;
- int ret;
-
- ast_assert(sdp_state != NULL);
-
- sdp = ast_sdp_translator_to_sdp(sdp_state->translator, remote);
- if (!sdp) {
- return -1;
- }
- ret = ast_sdp_state_set_remote_sdp(sdp_state, sdp);
- ao2_ref(sdp, -1);
- return ret;
-}
-
-int ast_sdp_state_is_offer_rejected(struct ast_sdp_state *sdp_state)
-{
- return sdp_state->remote_offer_rejected;
-}
-
-int ast_sdp_state_is_offerer(struct ast_sdp_state *sdp_state)
-{
- return sdp_state->role == SDP_ROLE_OFFERER;
-}
-
-int ast_sdp_state_is_answerer(struct ast_sdp_state *sdp_state)
-{
- return sdp_state->role == SDP_ROLE_ANSWERER;
-}
-
-int ast_sdp_state_restart_negotiations(struct ast_sdp_state *sdp_state)
-{
- ast_assert(sdp_state != NULL);
-
- ao2_cleanup(sdp_state->local_sdp);
- sdp_state->local_sdp = NULL;
-
- sdp_state->role = SDP_ROLE_NOT_SET;
- sdp_state->remote_offer_rejected = 0;
-
- if (sdp_state->negotiated_capabilities) {
- update_proposed_capabilities(sdp_state, sdp_state->negotiated_capabilities);
- }
-
- return 0;
-}
-
-int ast_sdp_state_update_local_topology(struct ast_sdp_state *sdp_state, struct ast_stream_topology *topology)
-{
- struct ast_stream_topology *merged_topology;
-
- ast_assert(sdp_state != NULL);
- ast_assert(topology != NULL);
-
- if (sdp_state->pending_topology_update) {
- merged_topology = merge_local_topologies(sdp_state,
- sdp_state->pending_topology_update, topology, 0);
- if (!merged_topology) {
- return -1;
- }
- ast_stream_topology_free(sdp_state->pending_topology_update);
- sdp_state->pending_topology_update = merged_topology;
- } else {
- sdp_state->pending_topology_update = ast_stream_topology_clone(topology);
- if (!sdp_state->pending_topology_update) {
- return -1;
- }
- }
-
- return 0;
-}
-
-void ast_sdp_state_set_local_address(struct ast_sdp_state *sdp_state, struct ast_sockaddr *address)
-{
- ast_assert(sdp_state != NULL);
-
- if (!address) {
- ast_sockaddr_setnull(&sdp_state->connection_address);
- } else {
- ast_sockaddr_copy(&sdp_state->connection_address, address);
- }
-}
-
-int ast_sdp_state_set_connection_address(struct ast_sdp_state *sdp_state, int stream_index,
- struct ast_sockaddr *address)
-{
- struct sdp_state_stream *stream_state;
- ast_assert(sdp_state != NULL);
-
- stream_state = sdp_state_get_stream(sdp_state, stream_index);
- if (!stream_state) {
- return -1;
- }
-
- if (!address) {
- ast_sockaddr_setnull(&stream_state->connection_address);
- } else {
- ast_sockaddr_copy(&stream_state->connection_address, address);
- }
-
- return 0;
-}
-
-void ast_sdp_state_set_global_locally_held(struct ast_sdp_state *sdp_state, unsigned int locally_held)
-{
- ast_assert(sdp_state != NULL);
-
- sdp_state->locally_held = locally_held ? 1 : 0;
-}
-
-unsigned int ast_sdp_state_get_global_locally_held(const struct ast_sdp_state *sdp_state)
-{
- ast_assert(sdp_state != NULL);
-
- return sdp_state->locally_held;
-}
-
-void ast_sdp_state_set_locally_held(struct ast_sdp_state *sdp_state,
- int stream_index, unsigned int locally_held)
-{
- struct sdp_state_stream *stream_state;
- ast_assert(sdp_state != NULL);
-
- locally_held = locally_held ? 1 : 0;
-
- stream_state = sdp_state_get_joint_stream(sdp_state, stream_index);
- if (stream_state) {
- stream_state->locally_held = locally_held;
- }
-
- stream_state = sdp_state_get_stream(sdp_state, stream_index);
- if (stream_state) {
- stream_state->locally_held = locally_held;
- }
-}
-
-unsigned int ast_sdp_state_get_locally_held(const struct ast_sdp_state *sdp_state,
- int stream_index)
-{
- struct sdp_state_stream *stream_state;
- ast_assert(sdp_state != NULL);
-
- stream_state = sdp_state_get_joint_stream(sdp_state, stream_index);
- if (!stream_state) {
- return 0;
- }
-
- return stream_state->locally_held;
-}
-
-unsigned int ast_sdp_state_get_remotely_held(const struct ast_sdp_state *sdp_state,
- int stream_index)
-{
- struct sdp_state_stream *stream_state;
-
- ast_assert(sdp_state != NULL);
-
- stream_state = sdp_state_get_joint_stream(sdp_state, stream_index);
- if (!stream_state) {
- return 0;
- }
-
- return stream_state->remotely_held;
-}
-
-void ast_sdp_state_set_t38_parameters(struct ast_sdp_state *sdp_state,
- int stream_index, struct ast_control_t38_parameters *params)
-{
- struct sdp_state_stream *stream_state;
- ast_assert(sdp_state != NULL && params != NULL);
-
- stream_state = sdp_state_get_stream(sdp_state, stream_index);
- if (stream_state) {
- stream_state->t38_local_params = *params;
- }
-}
-
-/*!
- * \brief Add SSRC-level attributes if appropriate.
- *
- * This function does nothing if the SDP options indicate not to add SSRC-level attributes.
- *
- * Currently, the only attribute added is cname, which is retrieved from the RTP instance.
- *
- * \param m_line The m_line on which to add the SSRC attributes
- * \param options Options that indicate what, if any, SSRC attributes to add
- * \param rtp RTP instance from which we get SSRC-level information
- */
-static void add_ssrc_attributes(struct ast_sdp_m_line *m_line, const struct ast_sdp_options *options,
- struct ast_rtp_instance *rtp)
-{
- struct ast_sdp_a_line *a_line;
- char attr_buffer[128];
-
- if (!ast_sdp_options_get_ssrc(options)) {
- return;
- }
-
- snprintf(attr_buffer, sizeof(attr_buffer), "%u cname:%s", ast_rtp_instance_get_ssrc(rtp),
- ast_rtp_instance_get_cname(rtp));
-
- a_line = ast_sdp_a_alloc("ssrc", attr_buffer);
- if (!a_line) {
- return;
- }
- ast_sdp_m_add_a(m_line, a_line);
-}
-
-/*!
- * \internal
- * \brief Create a declined m-line from a remote requested stream.
- * \since 15.0.0
- *
- * \details
- * Using the last received remote SDP create a declined stream
- * m-line for the requested stream. The stream may be unsupported.
- *
- * \param sdp Our SDP under construction to append the declined stream.
- * \param sdp_state
- * \param stream_index Which remote SDP stream we are declining.
- *
- * \retval 0 on success.
- * \retval -1 on failure.
- */
-static int sdp_add_m_from_declined_remote_stream(struct ast_sdp *sdp,
- const struct ast_sdp_state *sdp_state, int stream_index)
-{
- const struct ast_sdp_m_line *m_line_remote;
- struct ast_sdp_m_line *m_line;
- int idx;
-
- ast_assert(sdp && sdp_state && sdp_state->remote_sdp);
- ast_assert(stream_index < ast_sdp_get_m_count(sdp_state->remote_sdp));
-
- /*
- * The only way we can generate a declined unsupported stream
- * m-line is if the remote offered it to us.
- */
- m_line_remote = ast_sdp_get_m(sdp_state->remote_sdp, stream_index);
-
- /* Copy remote SDP stream m-line except for port number. */
- m_line = ast_sdp_m_alloc(m_line_remote->type, 0, m_line_remote->port_count,
- m_line_remote->proto, NULL);
- if (!m_line) {
- return -1;
- }
-
- /* Copy any m-line payload strings from the remote SDP */
- for (idx = 0; idx < ast_sdp_m_get_payload_count(m_line_remote); ++idx) {
- const struct ast_sdp_payload *payload_remote;
- struct ast_sdp_payload *payload;
-
- payload_remote = ast_sdp_m_get_payload(m_line_remote, idx);
- payload = ast_sdp_payload_alloc(payload_remote->fmt);
- if (!payload) {
- ast_sdp_m_free(m_line);
- return -1;
- }
- if (ast_sdp_m_add_payload(m_line, payload)) {
- ast_sdp_payload_free(payload);
- ast_sdp_m_free(m_line);
- return -1;
- }
- }
-
- if (ast_sdp_add_m(sdp, m_line)) {
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- return 0;
-}
-
-/*!
- * \internal
- * \brief Create a declined m-line for our SDP stream.
- * \since 15.0.0
- *
- * \param sdp Our SDP under construction to append the declined stream.
- * \param sdp_state
- * \param type Stream type we are declining.
- * \param stream_index Which remote SDP stream we are declining.
- *
- * \retval 0 on success.
- * \retval -1 on failure.
- */
-static int sdp_add_m_from_declined_stream(struct ast_sdp *sdp,
- const struct ast_sdp_state *sdp_state, enum ast_media_type type, int stream_index)
-{
- struct ast_sdp_m_line *m_line;
- const char *proto;
- const char *fmt;
- struct ast_sdp_payload *payload;
-
- if (sdp_state->role == SDP_ROLE_ANSWERER) {
- /* We are declining the remote stream or it is still declined. */
- return sdp_add_m_from_declined_remote_stream(sdp, sdp_state, stream_index);
- }
-
- /* Send declined remote stream in our offer if the type matches. */
- if (sdp_state->remote_sdp
- && stream_index < ast_sdp_get_m_count(sdp_state->remote_sdp)) {
- if (!sdp_is_stream_type_supported(type)
- || !strcasecmp(ast_sdp_get_m(sdp_state->remote_sdp, stream_index)->type,
- ast_codec_media_type2str(type))) {
- /* Stream is still declined */
- return sdp_add_m_from_declined_remote_stream(sdp, sdp_state, stream_index);
- }
- }
-
- /* Build a new declined stream in our offer. */
- switch (type) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- proto = "RTP/AVP";
- break;
- case AST_MEDIA_TYPE_IMAGE:
- proto = "udptl";
- break;
- default:
- /* Stream type not supported */
- ast_assert(0);
- return -1;
- }
- m_line = ast_sdp_m_alloc(ast_codec_media_type2str(type), 0, 1, proto, NULL);
- if (!m_line) {
- return -1;
- }
-
- /* Add a dummy static payload type */
- switch (type) {
- case AST_MEDIA_TYPE_AUDIO:
- fmt = "0"; /* ulaw */
- break;
- case AST_MEDIA_TYPE_VIDEO:
- fmt = "31"; /* H.261 */
- break;
- case AST_MEDIA_TYPE_IMAGE:
- fmt = "t38"; /* T.38 */
- break;
- default:
- /* Stream type not supported */
- ast_assert(0);
- ast_sdp_m_free(m_line);
- return -1;
- }
- payload = ast_sdp_payload_alloc(fmt);
- if (!payload || ast_sdp_m_add_payload(m_line, payload)) {
- ast_sdp_payload_free(payload);
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- if (ast_sdp_add_m(sdp, m_line)) {
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- return 0;
-}
-
-static int sdp_add_m_from_rtp_stream(struct ast_sdp *sdp, const struct ast_sdp_state *sdp_state,
- const struct sdp_state_capabilities *capabilities, int stream_index)
-{
- struct ast_stream *stream;
- struct ast_sdp_m_line *m_line;
- struct ast_format_cap *caps;
- int i;
- int rtp_code;
- int rtp_port;
- int min_packet_size = 0;
- int max_packet_size = 0;
- enum ast_media_type media_type;
- char tmp[64];
- struct sdp_state_stream *stream_state;
- struct ast_rtp_instance *rtp;
- struct ast_sdp_a_line *a_line;
- const struct ast_sdp_options *options;
- const char *direction;
-
- stream = ast_stream_topology_get_stream(capabilities->topology, stream_index);
-
- ast_assert(sdp && sdp_state && stream);
-
- options = sdp_state->options;
- caps = ast_stream_get_formats(stream);
-
- stream_state = AST_VECTOR_GET(&capabilities->streams, stream_index);
- if (stream_state->rtp && caps && ast_format_cap_count(caps)
- && AST_STREAM_STATE_REMOVED != ast_stream_get_state(stream)) {
- rtp = stream_state->rtp->instance;
- } else {
- /* This is a disabled stream */
- rtp = NULL;
- }
-
- if (rtp) {
- struct ast_sockaddr address_rtp;
-
- if (sdp_state_stream_get_connection_address(sdp_state, stream_state, &address_rtp)) {
- return -1;
- }
- rtp_port = ast_sockaddr_port(&address_rtp);
- } else {
- rtp_port = 0;
- }
-
- media_type = ast_stream_get_type(stream);
- if (!rtp_port) {
- /* Declined/disabled stream */
- return sdp_add_m_from_declined_stream(sdp, sdp_state, media_type, stream_index);
- }
-
- /* Stream is not declined/disabled */
- m_line = ast_sdp_m_alloc(ast_codec_media_type2str(media_type), rtp_port, 1,
- options->encryption != AST_SDP_ENCRYPTION_DISABLED ? "RTP/SAVP" : "RTP/AVP",
- NULL);
- if (!m_line) {
- return -1;
- }
-
- for (i = 0; i < ast_format_cap_count(caps); i++) {
- struct ast_format *format = ast_format_cap_get_format(caps, i);
-
- rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(rtp), 1,
- format, 0);
- if (rtp_code == -1) {
- ast_log(LOG_WARNING,"Unable to get rtp codec payload code for %s\n",
- ast_format_get_name(format));
- ao2_ref(format, -1);
- continue;
- }
-
- if (ast_sdp_m_add_format(m_line, options, rtp_code, 1, format, 0)) {
- ast_sdp_m_free(m_line);
- ao2_ref(format, -1);
- return -1;
- }
-
- if (ast_format_get_maximum_ms(format)
- && ((ast_format_get_maximum_ms(format) < max_packet_size)
- || !max_packet_size)) {
- max_packet_size = ast_format_get_maximum_ms(format);
- }
-
- ao2_ref(format, -1);
- }
-
- if (media_type != AST_MEDIA_TYPE_VIDEO
- && (options->dtmf == AST_SDP_DTMF_RFC_4733 || options->dtmf == AST_SDP_DTMF_AUTO)) {
- i = AST_RTP_DTMF;
- rtp_code = ast_rtp_codecs_payload_code(
- ast_rtp_instance_get_codecs(rtp), 0, NULL, i);
- if (-1 < rtp_code) {
- if (ast_sdp_m_add_format(m_line, options, rtp_code, 0, NULL, i)) {
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- snprintf(tmp, sizeof(tmp), "%d 0-16", rtp_code);
- a_line = ast_sdp_a_alloc("fmtp", tmp);
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- }
- }
-
- /* If ptime is set add it as an attribute */
- min_packet_size = ast_rtp_codecs_get_framing(ast_rtp_instance_get_codecs(rtp));
- if (!min_packet_size) {
- min_packet_size = ast_format_cap_get_framing(caps);
- }
- if (min_packet_size) {
- snprintf(tmp, sizeof(tmp), "%d", min_packet_size);
-
- a_line = ast_sdp_a_alloc("ptime", tmp);
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- }
-
- if (max_packet_size) {
- snprintf(tmp, sizeof(tmp), "%d", max_packet_size);
- a_line = ast_sdp_a_alloc("maxptime", tmp);
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- }
-
- if (sdp_state->locally_held || stream_state->locally_held) {
- if (stream_state->remotely_held) {
- direction = "inactive";
- } else {
- direction = "sendonly";
- }
- } else {
- if (stream_state->remotely_held) {
- direction = "recvonly";
- } else {
- /* Default is "sendrecv" */
- direction = NULL;
- }
- }
- if (direction) {
- a_line = ast_sdp_a_alloc(direction, "");
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- }
-
- add_ssrc_attributes(m_line, options, rtp);
-
- if (ast_sdp_add_m(sdp, m_line)) {
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- return 0;
-}
-
-/*! \brief Get Max T.38 Transmission rate from T38 capabilities */
-static unsigned int t38_get_rate(enum ast_control_t38_rate rate)
-{
- switch (rate) {
- case AST_T38_RATE_2400:
- return 2400;
- case AST_T38_RATE_4800:
- return 4800;
- case AST_T38_RATE_7200:
- return 7200;
- case AST_T38_RATE_9600:
- return 9600;
- case AST_T38_RATE_12000:
- return 12000;
- case AST_T38_RATE_14400:
- return 14400;
- default:
- return 0;
- }
-}
-
-static int sdp_add_m_from_udptl_stream(struct ast_sdp *sdp, const struct ast_sdp_state *sdp_state,
- const struct sdp_state_capabilities *capabilities, int stream_index)
-{
- struct ast_stream *stream;
- struct ast_sdp_m_line *m_line;
- struct ast_sdp_payload *payload;
- enum ast_media_type media_type;
- char tmp[64];
- struct sdp_state_udptl *udptl;
- struct ast_sdp_a_line *a_line;
- struct sdp_state_stream *stream_state;
- int udptl_port;
-
- stream = ast_stream_topology_get_stream(capabilities->topology, stream_index);
-
- ast_assert(sdp && sdp_state && stream);
-
- stream_state = AST_VECTOR_GET(&capabilities->streams, stream_index);
- if (stream_state->udptl
- && AST_STREAM_STATE_REMOVED != ast_stream_get_state(stream)) {
- udptl = stream_state->udptl;
- } else {
- /* This is a disabled stream */
- udptl = NULL;
- }
-
- if (udptl) {
- struct ast_sockaddr address_udptl;
-
- if (sdp_state_stream_get_connection_address(sdp_state, stream_state, &address_udptl)) {
- return -1;
- }
- udptl_port = ast_sockaddr_port(&address_udptl);
- } else {
- udptl_port = 0;
- }
-
- media_type = ast_stream_get_type(stream);
- if (!udptl_port) {
- /* Declined/disabled stream */
- return sdp_add_m_from_declined_stream(sdp, sdp_state, media_type, stream_index);
- }
-
- /* Stream is not declined/disabled */
- m_line = ast_sdp_m_alloc(ast_codec_media_type2str(media_type), udptl_port, 1,
- "udptl", NULL);
- if (!m_line) {
- return -1;
- }
-
- payload = ast_sdp_payload_alloc("t38");
- if (!payload || ast_sdp_m_add_payload(m_line, payload)) {
- ast_sdp_payload_free(payload);
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- snprintf(tmp, sizeof(tmp), "%u", stream_state->t38_local_params.version);
- a_line = ast_sdp_a_alloc("T38FaxVersion", tmp);
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- snprintf(tmp, sizeof(tmp), "%u", t38_get_rate(stream_state->t38_local_params.rate));
- a_line = ast_sdp_a_alloc("T38FaxMaxBitRate", tmp);
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- if (stream_state->t38_local_params.fill_bit_removal) {
- a_line = ast_sdp_a_alloc("T38FaxFillBitRemoval", "");
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- }
-
- if (stream_state->t38_local_params.transcoding_mmr) {
- a_line = ast_sdp_a_alloc("T38FaxTranscodingMMR", "");
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- }
-
- if (stream_state->t38_local_params.transcoding_jbig) {
- a_line = ast_sdp_a_alloc("T38FaxTranscodingJBIG", "");
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- }
-
- switch (stream_state->t38_local_params.rate_management) {
- case AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF:
- a_line = ast_sdp_a_alloc("T38FaxRateManagement", "transferredTCF");
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- break;
- case AST_T38_RATE_MANAGEMENT_LOCAL_TCF:
- a_line = ast_sdp_a_alloc("T38FaxRateManagement", "localTCF");
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- break;
- }
-
- snprintf(tmp, sizeof(tmp), "%u", ast_udptl_get_local_max_datagram(udptl->instance));
- a_line = ast_sdp_a_alloc("T38FaxMaxDatagram", tmp);
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- switch (ast_udptl_get_error_correction_scheme(udptl->instance)) {
- case UDPTL_ERROR_CORRECTION_NONE:
- break;
- case UDPTL_ERROR_CORRECTION_FEC:
- a_line = ast_sdp_a_alloc("T38FaxUdpEC", "t38UDPFEC");
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- break;
- case UDPTL_ERROR_CORRECTION_REDUNDANCY:
- a_line = ast_sdp_a_alloc("T38FaxUdpEC", "t38UDPRedundancy");
- if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
- ast_sdp_a_free(a_line);
- ast_sdp_m_free(m_line);
- return -1;
- }
- break;
- }
-
- if (ast_sdp_add_m(sdp, m_line)) {
- ast_sdp_m_free(m_line);
- return -1;
- }
-
- return 0;
-}
-
-/*!
- * \brief Create an SDP based on current SDP state
- *
- * \param sdp_state The current SDP state
- * \retval NULL Failed to create SDP
- * \retval non-NULL Newly-created SDP
- */
-static struct ast_sdp *sdp_create_from_state(const struct ast_sdp_state *sdp_state,
- const struct sdp_state_capabilities *capabilities)
-{
- struct ast_sdp *sdp = NULL;
- struct ast_stream_topology *topology;
- const struct ast_sdp_options *options;
- int stream_num;
- struct ast_sdp_o_line *o_line = NULL;
- struct ast_sdp_c_line *c_line = NULL;
- struct ast_sdp_s_line *s_line = NULL;
- struct ast_sdp_t_line *t_line = NULL;
- char *address_type;
- struct timeval tv = ast_tvnow();
- uint32_t t;
- int stream_count;
-
- options = sdp_state->options;
- topology = capabilities->topology;
-
- t = tv.tv_sec + 2208988800UL;
- address_type = (strchr(options->media_address, ':') ? "IP6" : "IP4");
-
- o_line = ast_sdp_o_alloc(options->sdpowner, t, t, address_type, options->media_address);
- if (!o_line) {
- goto error;
- }
- c_line = ast_sdp_c_alloc(address_type, options->media_address);
- if (!c_line) {
- goto error;
- }
- s_line = ast_sdp_s_alloc(options->sdpsession);
- if (!s_line) {
- goto error;
- }
- t_line = ast_sdp_t_alloc(0, 0);
- if (!t_line) {
- goto error;
- }
-
- sdp = ast_sdp_alloc(o_line, c_line, s_line, t_line);
- if (!sdp) {
- goto error;
- }
-
- stream_count = ast_stream_topology_get_count(topology);
- for (stream_num = 0; stream_num < stream_count; stream_num++) {
- switch (ast_stream_get_type(ast_stream_topology_get_stream(topology, stream_num))) {
- case AST_MEDIA_TYPE_AUDIO:
- case AST_MEDIA_TYPE_VIDEO:
- if (sdp_add_m_from_rtp_stream(sdp, sdp_state, capabilities, stream_num)) {
- goto error;
- }
- break;
- case AST_MEDIA_TYPE_IMAGE:
- if (sdp_add_m_from_udptl_stream(sdp, sdp_state, capabilities, stream_num)) {
- goto error;
- }
- break;
- case AST_MEDIA_TYPE_UNKNOWN:
- case AST_MEDIA_TYPE_TEXT:
- case AST_MEDIA_TYPE_END:
- /* Decline any of these streams from the remote. */
- if (sdp_add_m_from_declined_remote_stream(sdp, sdp_state, stream_num)) {
- goto error;
- }
- break;
- }
- }
-
- return sdp;
-
-error:
- if (sdp) {
- ao2_ref(sdp, -1);
- } else {
- ast_sdp_t_free(t_line);
- ast_sdp_s_free(s_line);
- ast_sdp_c_free(c_line);
- ast_sdp_o_free(o_line);
- }
-
- return NULL;
-}
diff --git a/main/sdp_translator.c b/main/sdp_translator.c
deleted file mode 100644
index 6fe330a60..000000000
--- a/main/sdp_translator.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#include "asterisk.h"
-#include "asterisk/sdp_options.h"
-#include "asterisk/sdp_translator.h"
-#include "asterisk/logger.h"
-#include "asterisk/utils.h"
-#include "asterisk/lock.h"
-
-AST_RWLOCK_DEFINE_STATIC(registered_ops_lock);
-static struct ast_sdp_translator_ops *registered_ops[AST_SDP_IMPL_END];
-
-int ast_sdp_register_translator(struct ast_sdp_translator_ops *ops)
-{
- SCOPED_WRLOCK(lock, &registered_ops_lock);
-
- if (ops->repr >= AST_SDP_IMPL_END) {
- ast_log(LOG_ERROR, "SDP translator has unrecognized representation\n");
- return -1;
- }
-
- if (registered_ops[ops->repr] != NULL) {
- ast_log(LOG_ERROR, "SDP_translator with this representation already registered\n");
- return -1;
- }
-
- registered_ops[ops->repr] = ops;
- ast_log(LOG_NOTICE, "Placed ops %p at slot %d\n", ops, ops->repr);
- return 0;
-}
-
-void ast_sdp_unregister_translator(struct ast_sdp_translator_ops *ops)
-{
- SCOPED_WRLOCK(lock, &registered_ops_lock);
-
- if (ops->repr >= AST_SDP_IMPL_END) {
- return;
- }
-
- registered_ops[ops->repr] = NULL;
-}
-
-struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_impl repr)
-{
- struct ast_sdp_translator *translator;
- SCOPED_RDLOCK(lock, &registered_ops_lock);
-
- if (registered_ops[repr] == NULL) {
- ast_log(LOG_NOTICE, "No registered SDP translator with representation %d\n", repr);
- return NULL;
- }
-
- translator = ast_calloc(1, sizeof(*translator));
- if (!translator) {
- return NULL;
- }
-
- translator->ops = registered_ops[repr];
-
- translator->translator_priv = translator->ops->translator_new();
- if (!translator->translator_priv) {
- ast_free(translator);
- return NULL;
- }
-
- return translator;
-}
-
-void ast_sdp_translator_free(struct ast_sdp_translator *translator)
-{
- if (!translator) {
- return;
- }
- translator->ops->translator_free(translator->translator_priv);
- ast_free(translator);
-}
-
-struct ast_sdp *ast_sdp_translator_to_sdp(struct ast_sdp_translator *translator,
- const void *native_sdp)
-{
- return translator->ops->to_sdp(native_sdp, translator->translator_priv);
-}
-
-const void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator,
- const struct ast_sdp *ast_sdp)
-{
- return translator->ops->from_sdp(ast_sdp, translator->translator_priv);
-}
diff --git a/main/stasis_bridges.c b/main/stasis_bridges.c
index 4b68559de..59b9685ef 100644
--- a/main/stasis_bridges.c
+++ b/main/stasis_bridges.c
@@ -246,8 +246,7 @@ struct ast_bridge_snapshot *ast_bridge_snapshot_create(struct ast_bridge *bridge
return NULL;
}
- if (ast_string_field_init(snapshot, 128)
- || ast_string_field_init_extended(snapshot, video_source_id)) {
+ if (ast_string_field_init(snapshot, 128)) {
ao2_ref(snapshot, -1);
return NULL;
diff --git a/main/stream.c b/main/stream.c
index 61eef2504..dd3e765f6 100644
--- a/main/stream.c
+++ b/main/stream.c
@@ -34,6 +34,15 @@
#include "asterisk/strings.h"
#include "asterisk/format.h"
#include "asterisk/format_cap.h"
+#include "asterisk/vector.h"
+#include "asterisk/config.h"
+#include "asterisk/rtp_engine.h"
+
+struct ast_stream_metadata_entry {
+ size_t length;
+ int value_start;
+ char name_value[0];
+};
struct ast_stream {
/*!
@@ -57,19 +66,19 @@ struct ast_stream {
enum ast_stream_state state;
/*!
- * \brief Opaque stream data
+ * \brief Stream metadata vector
*/
- void *data[AST_STREAM_DATA_SLOT_MAX];
+ struct ast_variable *metadata;
/*!
- * \brief What to do with data when the stream is freed
+ * \brief The group that the stream is part of
*/
- ast_stream_data_free_fn data_free_fn[AST_STREAM_DATA_SLOT_MAX];
+ int group;
/*!
- * \brief The group that the stream is part of
+ * \brief The rtp_codecs used by the stream
*/
- int group;
+ struct ast_rtp_codecs *rtp_codecs;
/*!
* \brief Name for the stream within the context of the channel it is on
@@ -105,7 +114,6 @@ struct ast_stream *ast_stream_clone(const struct ast_stream *stream, const char
{
struct ast_stream *new_stream;
size_t stream_size;
- int idx;
const char *stream_name;
if (!stream) {
@@ -126,27 +134,23 @@ struct ast_stream *ast_stream_clone(const struct ast_stream *stream, const char
ao2_ref(new_stream->formats, +1);
}
- /* We cannot clone the opaque data because we don't know how. */
- for (idx = 0; idx < AST_STREAM_DATA_SLOT_MAX; ++idx) {
- new_stream->data[idx] = NULL;
- new_stream->data_free_fn[idx] = NULL;
- }
+ new_stream->metadata = ast_stream_get_metadata_list(stream);
+
+ /* rtp_codecs aren't cloned */
return new_stream;
}
void ast_stream_free(struct ast_stream *stream)
{
- int i;
-
if (!stream) {
return;
}
- for (i = 0; i < AST_STREAM_DATA_SLOT_MAX; i++) {
- if (stream->data_free_fn[i]) {
- stream->data_free_fn[i](stream->data[i]);
- }
+ ast_variables_destroy(stream->metadata);
+
+ if (stream->rtp_codecs) {
+ ast_rtp_codecs_payloads_destroy(stream->rtp_codecs);
}
ao2_cleanup(stream->formats);
@@ -238,22 +242,81 @@ enum ast_stream_state ast_stream_str2state(const char *str)
return AST_STREAM_STATE_REMOVED;
}
-void *ast_stream_get_data(struct ast_stream *stream, enum ast_stream_data_slot slot)
+const char *ast_stream_get_metadata(const struct ast_stream *stream, const char *m_key)
{
- ast_assert(stream != NULL);
+ struct ast_variable *v;
+
+ ast_assert_return(stream != NULL, NULL);
+ ast_assert_return(m_key != NULL, NULL);
- return stream->data[slot];
+ for (v = stream->metadata; v; v = v->next) {
+ if (strcmp(v->name, m_key) == 0) {
+ return v->value;
+ }
+ }
+
+ return NULL;
}
-void *ast_stream_set_data(struct ast_stream *stream, enum ast_stream_data_slot slot,
- void *data, ast_stream_data_free_fn data_free_fn)
+struct ast_variable *ast_stream_get_metadata_list(const struct ast_stream *stream)
{
- ast_assert(stream != NULL);
+ struct ast_variable *v;
+ struct ast_variable *vout = NULL;
+
+ ast_assert_return(stream != NULL, NULL);
+
+ for (v = stream->metadata; v; v = v->next) {
+ struct ast_variable *vt = ast_variable_new(v->name, v->value, "");
+
+ if (!vt) {
+ ast_variables_destroy(vout);
+ return NULL;
+ }
+
+ ast_variable_list_append(&vout, vt);
+ }
- stream->data[slot] = data;
- stream->data_free_fn[slot] = data_free_fn;
+ return vout;
+}
- return data;
+int ast_stream_set_metadata(struct ast_stream *stream, const char *m_key, const char *value)
+{
+ struct ast_variable *v;
+ struct ast_variable *prev;
+
+ ast_assert_return(stream != NULL, -1);
+ ast_assert_return(m_key != NULL, -1);
+
+ prev = NULL;
+ v = stream->metadata;
+ while(v) {
+ struct ast_variable *next = v->next;
+ if (strcmp(v->name, m_key) == 0) {
+ if (prev) {
+ prev->next = next;
+ } else {
+ stream->metadata = next;
+ }
+ ast_free(v);
+ break;
+ } else {
+ prev = v;
+ }
+ v = next;
+ }
+
+ if (!value) {
+ return 0;
+ }
+
+ v = ast_variable_new(m_key, value, "");
+ if (!v) {
+ return -1;
+ }
+
+ ast_variable_list_append(&stream->metadata, v);
+
+ return 0;
}
int ast_stream_get_position(const struct ast_stream *stream)
@@ -263,6 +326,24 @@ int ast_stream_get_position(const struct ast_stream *stream)
return stream->position;
}
+struct ast_rtp_codecs *ast_stream_get_rtp_codecs(const struct ast_stream *stream)
+{
+ ast_assert(stream != NULL);
+
+ return stream->rtp_codecs;
+}
+
+void ast_stream_set_rtp_codecs(struct ast_stream *stream, struct ast_rtp_codecs *rtp_codecs)
+{
+ ast_assert(stream != NULL);
+
+ if (stream->rtp_codecs) {
+ ast_rtp_codecs_payloads_destroy(rtp_codecs);
+ }
+
+ stream->rtp_codecs = rtp_codecs;
+}
+
#define TOPOLOGY_INITIAL_STREAM_COUNT 2
struct ast_stream_topology *ast_stream_topology_alloc(void)
{
diff --git a/menuselect/Makefile b/menuselect/Makefile
index c2c9373f4..d949efd55 100644
--- a/menuselect/Makefile
+++ b/menuselect/Makefile
@@ -24,6 +24,14 @@ endif
OBJS:=menuselect.o strcompat.o
CFLAGS+=-g -D_GNU_SOURCE -Wall
+ifneq ($(findstring dragonfly,$(OSARCH)),)
+ CFLAGS += -isystem /usr/local/include
+else ifneq ($(findstring netbsd,$(OSARCH)),)
+ CFLAGS += -isystem /usr/pkg/include
+else ifneq ($(findstring bsd,$(OSARCH)),)
+ CFLAGS += -isystem /usr/local/include
+endif
+
ifeq ($(MENUSELECT_DEBUG),yes)
CFLAGS += -DMENUSELECT_DEBUG
endif
diff --git a/menuselect/autoconfig.h.in b/menuselect/autoconfig.h.in
index 3e1e18990..f1745516b 100644
--- a/menuselect/autoconfig.h.in
+++ b/menuselect/autoconfig.h.in
@@ -3,10 +3,6 @@
#ifndef MENUSELECT_AUTOCONFIG_H
#define MENUSELECT_AUTOCONFIG_H
-#ifndef _REENTRANT
-#define _REENTRANT
-#endif
-
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
systems. This function is required for `alloca.c' support on those systems.
diff --git a/menuselect/configure b/menuselect/configure
index 6e5331edd..7cbe47756 100755
--- a/menuselect/configure
+++ b/menuselect/configure
@@ -2320,33 +2320,18 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
HOST_OS=${host_os}
-PBX_WINARCH=0
case "${host_os}" in
- freebsd*)
- OSARCH=FreeBSD
+ *dragonfly*)
+ CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
+ LDFLAGS="${LDFLAGS} -L/usr/local/lib"
;;
- netbsd*)
- OSARCH=NetBSD
+ *netbsd*)
+ CPPFLAGS="${CPPFLAGS} -I/usr/pkg/include"
+ LDFLAGS="${LDFLAGS} -L/usr/pkg/lib"
;;
- openbsd*)
- OSARCH=OpenBSD
- ;;
- solaris*)
- OSARCH=SunOS
- ;;
- mingw32)
- OSARCH=mingw32
- PBX_WINARCH=1
- ;;
- cygwin)
- OSARCH=cygwin
- PBX_WINARCH=1
- ;;
- linux-gnueabi)
- OSARCH=linux-gnu
- ;;
- *)
- OSARCH=${host_os}
+ *bsd*)
+ CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
+ LDFLAGS="${LDFLAGS} -L/usr/local/lib"
;;
esac
@@ -4392,7 +4377,7 @@ fi
if test ! "x${CONFIG_LIBXML2}" = xNo; then
LIBXML2_INCLUDE=$(${CONFIG_LIBXML2} --cflags)
- LIBXML2_INCLUDE=$(echo ${LIBXML2_INCLUDE} | $SED -e "s|-I|-I${LIBXML2_DIR}|g")
+ LIBXML2_INCLUDE=$(echo ${LIBXML2_INCLUDE} | $SED -e "s|-I|-I${LIBXML2_DIR}|g" -e "s|-std=c99||g")
LIBXML2_LIB=$(${CONFIG_LIBXML2} --libs)
LIBXML2_LIB=$(echo ${LIBXML2_LIB} | $SED -e "s|-L|-L${LIBXML2_DIR}|g")
@@ -4633,7 +4618,7 @@ else
$as_echo "yes" >&6; }
PBX_GTK2=1
- GTK2_INCLUDE="$GTK2_CFLAGS"
+ GTK2_INCLUDE=$(echo ${GTK2_CFLAGS} | $SED -e "s|-std=c99||g")
GTK2_LIB="$GTK2_LIBS"
$as_echo "#define HAVE_GTK2 1" >>confdefs.h
diff --git a/menuselect/configure.ac b/menuselect/configure.ac
index 2dd4ed652..4a2d0acc2 100644
--- a/menuselect/configure.ac
+++ b/menuselect/configure.ac
@@ -1,5 +1,3 @@
-# Process this file with autoconf to produce a configure script.
-
AC_PREREQ(2.59)
m4_define([MENUSELECT_VERSION],
@@ -16,49 +14,29 @@ AC_CONFIG_HEADER(autoconfig.h)
AC_COPYRIGHT("Menuselect")
-AC_CANONICAL_BUILD
AC_CANONICAL_HOST
HOST_OS=${host_os}
AC_SUBST(HOST_OS)
-PBX_WINARCH=0
case "${host_os}" in
- freebsd*)
- OSARCH=FreeBSD
- ;;
- netbsd*)
- OSARCH=NetBSD
- ;;
- openbsd*)
- OSARCH=OpenBSD
- ;;
- solaris*)
- OSARCH=SunOS
+ *dragonfly*)
+ CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
+ LDFLAGS="${LDFLAGS} -L/usr/local/lib"
;;
- mingw32)
- OSARCH=mingw32
- PBX_WINARCH=1
+ *netbsd*)
+ CPPFLAGS="${CPPFLAGS} -I/usr/pkg/include"
+ LDFLAGS="${LDFLAGS} -L/usr/pkg/lib"
;;
- cygwin)
- OSARCH=cygwin
- PBX_WINARCH=1
- ;;
- linux-gnueabi)
- OSARCH=linux-gnu
- ;;
- *)
- OSARCH=${host_os}
+ *bsd*)
+ CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
+ LDFLAGS="${LDFLAGS} -L/usr/local/lib"
;;
esac
AH_TOP(
#ifndef MENUSELECT_AUTOCONFIG_H
#define MENUSELECT_AUTOCONFIG_H
-
-#ifndef _REENTRANT
-#define _REENTRANT
-#endif
)
AH_BOTTOM([#endif])
diff --git a/res/Makefile b/res/Makefile
index ecaa03d3c..ec3417b35 100644
--- a/res/Makefile
+++ b/res/Makefile
@@ -45,7 +45,8 @@ endif
$(ECHO_PREFIX) echo " [FLEX] $< -> $@"
$(CMD_PREFIX) (cd ael; $(FLEX) ael.flex)
$(CMD_PREFIX) sed 's@#if __STDC_VERSION__ >= 199901L@#if !defined __STDC_VERSION__ || __STDC_VERSION__ >= 199901L@' $@ > $@.fix
- $(CMD_PREFIX) echo "#include \"asterisk.h\"" > $@
+ $(CMD_PREFIX) echo "#define ASTMM_LIBC ASTMM_REDIRECT" > $@
+ $(CMD_PREFIX) echo "#include \"asterisk.h\"" >> $@
$(CMD_PREFIX) echo >> $@
$(CMD_PREFIX) cat $@.fix >> $@
$(CMD_PREFIX) rm $@.fix
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 55b14c934..1c8728cf7 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -333,7 +333,6 @@ static int ast_moh_files_next(struct ast_channel *chan)
}
} else {
state->announcement = 0;
- state->samples = 0;
}
if (!state->class->total_files) {
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 7c9929740..19e6e1d13 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -2743,7 +2743,7 @@ static int register_service(void *data)
int ast_sip_register_service(pjsip_module *module)
{
- return ast_sip_push_task_synchronous(NULL, register_service, &module);
+ return ast_sip_push_task_wait_servant(NULL, register_service, &module);
}
static int unregister_service(void *data)
@@ -2759,7 +2759,7 @@ static int unregister_service(void *data)
void ast_sip_unregister_service(pjsip_module *module)
{
- ast_sip_push_task_synchronous(NULL, unregister_service, &module);
+ ast_sip_push_task_wait_servant(NULL, unregister_service, &module);
}
static struct ast_sip_authenticator *registered_authenticator;
@@ -3009,7 +3009,7 @@ static char *cli_dump_endpt(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
return CLI_SHOWUSAGE;
}
- ast_sip_push_task_synchronous(NULL, do_cli_dump_endpt, a);
+ ast_sip_push_task_wait_servant(NULL, do_cli_dump_endpt, a);
return CLI_SUCCESS;
}
@@ -3801,8 +3801,6 @@ int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
{
const pjsip_method *pmethod = get_pjsip_method(method);
- ast_assert(endpoint != NULL);
-
if (!pmethod) {
ast_log(LOG_WARNING, "Unknown method '%s'. Cannot send request\n", method);
return -1;
@@ -3811,6 +3809,7 @@ int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
if (dlg) {
return create_in_dialog_request(pmethod, dlg, tdata);
} else {
+ ast_assert(endpoint != NULL);
return create_out_of_dialog_request(pmethod, endpoint, uri, contact, tdata);
}
}
@@ -4485,21 +4484,30 @@ static int serializer_pool_setup(void)
return 0;
}
+static struct ast_taskprocessor *serializer_pool_pick(void)
+{
+ struct ast_taskprocessor *serializer;
+
+ unsigned int pos;
+
+ /*
+ * Pick a serializer to use from the pool.
+ *
+ * Note: We don't care about any reentrancy behavior
+ * when incrementing serializer_pool_pos. If it gets
+ * incorrectly incremented it doesn't matter.
+ */
+ pos = serializer_pool_pos++;
+ pos %= SERIALIZER_POOL_SIZE;
+ serializer = serializer_pool[pos];
+
+ return serializer;
+}
+
int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
{
if (!serializer) {
- unsigned int pos;
-
- /*
- * Pick a serializer to use from the pool.
- *
- * Note: We don't care about any reentrancy behavior
- * when incrementing serializer_pool_pos. If it gets
- * incorrectly incremented it doesn't matter.
- */
- pos = serializer_pool_pos++;
- pos %= SERIALIZER_POOL_SIZE;
- serializer = serializer_pool[pos];
+ serializer = serializer_pool_pick();
}
return ast_taskprocessor_push(serializer, sip_task, task_data);
@@ -4523,9 +4531,8 @@ static int sync_task(void *data)
/*
* Once we unlock std->lock after signaling, we cannot access
- * std again. The thread waiting within
- * ast_sip_push_task_synchronous() is free to continue and
- * release its local variable (std).
+ * std again. The thread waiting within ast_sip_push_task_wait()
+ * is free to continue and release its local variable (std).
*/
ast_mutex_lock(&std->lock);
std->complete = 1;
@@ -4535,15 +4542,11 @@ static int sync_task(void *data)
return ret;
}
-int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
+static int ast_sip_push_task_wait(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
{
/* This method is an onion */
struct sync_task_data std;
- if (ast_sip_thread_is_servant()) {
- return sip_task(task_data);
- }
-
memset(&std, 0, sizeof(std));
ast_mutex_init(&std.lock);
ast_cond_init(&std.cond, NULL);
@@ -4567,6 +4570,42 @@ int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*si
return std.fail;
}
+int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
+{
+ if (ast_sip_thread_is_servant()) {
+ return sip_task(task_data);
+ }
+
+ return ast_sip_push_task_wait(serializer, sip_task, task_data);
+}
+
+int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
+{
+ return ast_sip_push_task_wait_servant(serializer, sip_task, task_data);
+}
+
+int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
+{
+ if (!serializer) {
+ /* Caller doesn't care which PJSIP serializer the task executes under. */
+ serializer = serializer_pool_pick();
+ if (!serializer) {
+ /* No serializer picked to execute the task */
+ return -1;
+ }
+ }
+ if (ast_taskprocessor_is_task(serializer)) {
+ /*
+ * We are the requested serializer so we must execute
+ * the task now or deadlock waiting on ourself to
+ * execute it.
+ */
+ return sip_task(task_data);
+ }
+
+ return ast_sip_push_task_wait(serializer, sip_task, task_data);
+}
+
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
{
size_t chars_to_copy = MIN(size - 1, pj_strlen(src));
@@ -5192,7 +5231,7 @@ static int reload_module(void)
* We must wait for the reload to complete so multiple
* reloads cannot happen at the same time.
*/
- if (ast_sip_push_task_synchronous(NULL, reload_configuration_task, NULL)) {
+ if (ast_sip_push_task_wait_servant(NULL, reload_configuration_task, NULL)) {
ast_log(LOG_WARNING, "Failed to reload PJSIP\n");
return -1;
}
@@ -5209,7 +5248,7 @@ static int unload_module(void)
/* The thread this is called from cannot call PJSIP/PJLIB functions,
* so we have to push the work to the threadpool to handle
*/
- ast_sip_push_task_synchronous(NULL, unload_pjsip, NULL);
+ ast_sip_push_task_wait_servant(NULL, unload_pjsip, NULL);
ast_sip_destroy_scheduler();
serializer_pool_shutdown();
ast_threadpool_shutdown(sip_threadpool);
diff --git a/res/res_pjsip/config_system.c b/res/res_pjsip/config_system.c
index dfd92404b..ed2b5d232 100644
--- a/res/res_pjsip/config_system.c
+++ b/res/res_pjsip/config_system.c
@@ -282,5 +282,5 @@ static int system_create_resolver_and_set_nameservers(void *data)
void ast_sip_initialize_dns(void)
{
- ast_sip_push_task_synchronous(NULL, system_create_resolver_and_set_nameservers, NULL);
+ ast_sip_push_task_wait_servant(NULL, system_create_resolver_and_set_nameservers, NULL);
}
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index 15c03769b..dd7c7049d 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -267,7 +267,7 @@ static void sip_transport_state_destroy(void *obj)
{
struct ast_sip_transport_state *state = obj;
- ast_sip_push_task_synchronous(NULL, destroy_sip_transport_state, state);
+ ast_sip_push_task_wait_servant(NULL, destroy_sip_transport_state, state);
}
/*! \brief Destructor for ast_sip_transport state information */
diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c
index 22da80577..6e79dc40b 100644
--- a/res/res_pjsip/location.c
+++ b/res/res_pjsip/location.c
@@ -133,11 +133,6 @@ static void *contact_alloc(const char *name)
return NULL;
}
- ast_string_field_init_extended(contact, endpoint_name);
- ast_string_field_init_extended(contact, reg_server);
- ast_string_field_init_extended(contact, via_addr);
- ast_string_field_init_extended(contact, call_id);
-
/* Dynamic contacts are delimited with ";@" and static ones with "@@" */
if ((aor_separator = strstr(id, ";@")) || (aor_separator = strstr(id, "@@"))) {
*aor_separator = '\0';
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 3094f248e..fb84a1f60 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -2248,8 +2248,6 @@ void *ast_sip_endpoint_alloc(const char *name)
return NULL;
}
- ast_string_field_init_extended(endpoint, incoming_mwi_mailbox);
-
if (!(endpoint->media.codecs = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
ao2_cleanup(endpoint);
return NULL;
diff --git a/res/res_pjsip/pjsip_scheduler.c b/res/res_pjsip/pjsip_scheduler.c
index e4459da66..bbf666fd7 100644
--- a/res/res_pjsip/pjsip_scheduler.c
+++ b/res/res_pjsip/pjsip_scheduler.c
@@ -28,6 +28,7 @@
#include "asterisk/res_pjsip.h"
#include "include/res_pjsip_private.h"
#include "asterisk/res_pjsip_cli.h"
+#include "asterisk/taskprocessor.h"
#define TASK_BUCKETS 53
@@ -36,31 +37,31 @@ static struct ao2_container *tasks;
static int task_count;
struct ast_sip_sched_task {
- /*! ast_sip_sched task id */
- uint32_t task_id;
- /*! ast_sched scheudler id */
- int current_scheduler_id;
- /*! task is currently running */
- int is_running;
- /*! task */
- ast_sip_task task;
+ /*! The serializer to be used (if any) (Holds a ref) */
+ struct ast_taskprocessor *serializer;
/*! task data */
void *task_data;
- /*! reschedule interval in milliseconds */
- int interval;
- /*! the time the task was queued */
+ /*! task function */
+ ast_sip_task task;
+ /*! the time the task was originally scheduled/queued */
struct timeval when_queued;
/*! the last time the task was started */
struct timeval last_start;
/*! the last time the task was ended */
struct timeval last_end;
+ /*! When the periodic task is next expected to run */
+ struct timeval next_periodic;
+ /*! reschedule interval in milliseconds */
+ int interval;
+ /*! ast_sched scheudler id */
+ int current_scheduler_id;
+ /*! task is currently running */
+ int is_running;
/*! times run */
int run_count;
/*! the task reschedule, cleanup and policy flags */
enum ast_sip_scheduler_task_flags flags;
- /*! the serializer to be used (if any) */
- struct ast_taskprocessor *serializer;
- /* A name to be associated with the task */
+ /*! A name to be associated with the task */
char name[0];
};
@@ -76,14 +77,22 @@ static int push_to_serializer(const void *data);
*/
static int run_task(void *data)
{
- RAII_VAR(struct ast_sip_sched_task *, schtd, ao2_bump(data), ao2_cleanup);
+ RAII_VAR(struct ast_sip_sched_task *, schtd, data, ao2_cleanup);
int res;
int delay;
+ if (!schtd->interval) {
+ /* Task was cancelled while waiting to be executed by the serializer */
+ return -1;
+ }
+
+ if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+ ast_log(LOG_DEBUG, "Sched %p: Running %s\n", schtd, schtd->name);
+ }
ao2_lock(schtd);
schtd->last_start = ast_tvnow();
schtd->is_running = 1;
- schtd->run_count++;
+ ++schtd->run_count;
ao2_unlock(schtd);
res = schtd->task(schtd->task_data);
@@ -93,10 +102,10 @@ static int run_task(void *data)
schtd->last_end = ast_tvnow();
/*
- * Don't restart if the task returned 0 or if the interval
+ * Don't restart if the task returned <= 0 or if the interval
* was set to 0 while the task was running
*/
- if (!res || !schtd->interval) {
+ if (res <= 0 || !schtd->interval) {
schtd->interval = 0;
ao2_unlock(schtd);
ao2_unlink(tasks, schtd);
@@ -110,18 +119,31 @@ static int run_task(void *data)
if (schtd->flags & AST_SIP_SCHED_TASK_DELAY) {
delay = schtd->interval;
} else {
- delay = schtd->interval - (ast_tvdiff_ms(schtd->last_end, schtd->last_start) % schtd->interval);
+ int64_t diff;
+
+ /* Determine next periodic interval we need to expire. */
+ do {
+ schtd->next_periodic = ast_tvadd(schtd->next_periodic,
+ ast_samp2tv(schtd->interval, 1000));
+ diff = ast_tvdiff_ms(schtd->next_periodic, schtd->last_end);
+ } while (diff <= 0);
+ delay = diff;
}
- schtd->current_scheduler_id = ast_sched_add(scheduler_context, delay, push_to_serializer, (const void *)schtd);
+ schtd->current_scheduler_id = ast_sched_add(scheduler_context, delay, push_to_serializer, schtd);
if (schtd->current_scheduler_id < 0) {
schtd->interval = 0;
ao2_unlock(schtd);
+ ast_log(LOG_ERROR, "Sched %p: Failed to reschedule task %s\n", schtd, schtd->name);
ao2_unlink(tasks, schtd);
return -1;
}
ao2_unlock(schtd);
+ if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+ ast_log(LOG_DEBUG, "Sched %p: Rescheduled %s for %d ms\n", schtd, schtd->name,
+ delay);
+ }
return 0;
}
@@ -133,9 +155,32 @@ static int run_task(void *data)
static int push_to_serializer(const void *data)
{
struct ast_sip_sched_task *schtd = (struct ast_sip_sched_task *)data;
+ int sched_id;
+ ao2_lock(schtd);
+ sched_id = schtd->current_scheduler_id;
+ schtd->current_scheduler_id = -1;
+ ao2_unlock(schtd);
+ if (sched_id < 0) {
+ /* Task was cancelled while waiting on the lock */
+ return 0;
+ }
+
+ if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+ ast_log(LOG_DEBUG, "Sched %p: Ready to run %s\n", schtd, schtd->name);
+ }
+ ao2_t_ref(schtd, +1, "Give ref to run_task()");
if (ast_sip_push_task(schtd->serializer, run_task, schtd)) {
- ao2_ref(schtd, -1);
+ /*
+ * Oh my. Have to cancel the scheduled item because we
+ * unexpectedly cannot run it anymore.
+ */
+ ao2_unlink(tasks, schtd);
+ ao2_lock(schtd);
+ schtd->interval = 0;
+ ao2_unlock(schtd);
+
+ ao2_t_ref(schtd, -1, "Failed so release run_task() ref");
}
return 0;
@@ -144,48 +189,54 @@ static int push_to_serializer(const void *data)
int ast_sip_sched_task_cancel(struct ast_sip_sched_task *schtd)
{
int res;
+ int sched_id;
- if (!ao2_ref_and_lock(schtd)) {
- return -1;
- }
-
- if (schtd->current_scheduler_id < 0 || schtd->interval <= 0) {
- ao2_unlock_and_unref(schtd);
- return 0;
+ if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+ ast_log(LOG_DEBUG, "Sched %p: Canceling %s\n", schtd, schtd->name);
}
+ /*
+ * Prevent any tasks in the serializer queue from
+ * running and restarting the scheduled item on us
+ * first.
+ */
+ ao2_lock(schtd);
schtd->interval = 0;
- ao2_unlock_and_unref(schtd);
+
+ sched_id = schtd->current_scheduler_id;
+ schtd->current_scheduler_id = -1;
+ ao2_unlock(schtd);
+ res = ast_sched_del(scheduler_context, sched_id);
+
ao2_unlink(tasks, schtd);
- res = ast_sched_del(scheduler_context, schtd->current_scheduler_id);
return res;
}
int ast_sip_sched_task_cancel_by_name(const char *name)
{
- RAII_VAR(struct ast_sip_sched_task *, schtd, NULL, ao2_cleanup);
+ int res;
+ struct ast_sip_sched_task *schtd;
if (ast_strlen_zero(name)) {
return -1;
}
- schtd = ao2_find(tasks, name, OBJ_SEARCH_KEY | OBJ_NOLOCK);
+ schtd = ao2_find(tasks, name, OBJ_SEARCH_KEY);
if (!schtd) {
return -1;
}
- return ast_sip_sched_task_cancel(schtd);
+ res = ast_sip_sched_task_cancel(schtd);
+ ao2_ref(schtd, -1);
+ return res;
}
int ast_sip_sched_task_get_times(struct ast_sip_sched_task *schtd,
struct timeval *queued, struct timeval *last_start, struct timeval *last_end)
{
- if (!ao2_ref_and_lock(schtd)) {
- return -1;
- }
-
+ ao2_lock(schtd);
if (queued) {
memcpy(queued, &schtd->when_queued, sizeof(struct timeval));
}
@@ -195,8 +246,7 @@ int ast_sip_sched_task_get_times(struct ast_sip_sched_task *schtd,
if (last_end) {
memcpy(last_end, &schtd->last_end, sizeof(struct timeval));
}
-
- ao2_unlock_and_unref(schtd);
+ ao2_unlock(schtd);
return 0;
}
@@ -204,18 +254,21 @@ int ast_sip_sched_task_get_times(struct ast_sip_sched_task *schtd,
int ast_sip_sched_task_get_times_by_name(const char *name,
struct timeval *queued, struct timeval *last_start, struct timeval *last_end)
{
- RAII_VAR(struct ast_sip_sched_task *, schtd, NULL, ao2_cleanup);
+ int res;
+ struct ast_sip_sched_task *schtd;
if (ast_strlen_zero(name)) {
return -1;
}
- schtd = ao2_find(tasks, name, OBJ_SEARCH_KEY | OBJ_NOLOCK);
+ schtd = ao2_find(tasks, name, OBJ_SEARCH_KEY);
if (!schtd) {
return -1;
}
- return ast_sip_sched_task_get_times(schtd, queued, last_start, last_end);
+ res = ast_sip_sched_task_get_times(schtd, queued, last_start, last_end);
+ ao2_ref(schtd, -1);
+ return res;
}
int ast_sip_sched_task_get_name(struct ast_sip_sched_task *schtd, char *name, size_t maxlen)
@@ -224,13 +277,9 @@ int ast_sip_sched_task_get_name(struct ast_sip_sched_task *schtd, char *name, si
return -1;
}
- if (!ao2_ref_and_lock(schtd)) {
- return -1;
- }
-
+ ao2_lock(schtd);
ast_copy_string(name, schtd->name, maxlen);
-
- ao2_unlock_and_unref(schtd);
+ ao2_unlock(schtd);
return 0;
}
@@ -241,9 +290,7 @@ int ast_sip_sched_task_get_next_run(struct ast_sip_sched_task *schtd)
struct timeval since_when;
struct timeval now;
- if (!ao2_ref_and_lock(schtd)) {
- return -1;
- }
+ ao2_lock(schtd);
if (schtd->interval) {
delay = schtd->interval;
@@ -262,103 +309,136 @@ int ast_sip_sched_task_get_next_run(struct ast_sip_sched_task *schtd)
delay = -1;
}
- ao2_unlock_and_unref(schtd);
+ ao2_unlock(schtd);
return delay;
}
int ast_sip_sched_task_get_next_run_by_name(const char *name)
{
- RAII_VAR(struct ast_sip_sched_task *, schtd, NULL, ao2_cleanup);
+ int next_run;
+ struct ast_sip_sched_task *schtd;
if (ast_strlen_zero(name)) {
return -1;
}
- schtd = ao2_find(tasks, name, OBJ_SEARCH_KEY | OBJ_NOLOCK);
+ schtd = ao2_find(tasks, name, OBJ_SEARCH_KEY);
if (!schtd) {
return -1;
}
- return ast_sip_sched_task_get_next_run(schtd);
+ next_run = ast_sip_sched_task_get_next_run(schtd);
+ ao2_ref(schtd, -1);
+ return next_run;
}
int ast_sip_sched_is_task_running(struct ast_sip_sched_task *schtd)
{
- if (!schtd) {
- return 0;
- }
-
- return schtd->is_running;
+ return schtd ? schtd->is_running : 0;
}
int ast_sip_sched_is_task_running_by_name(const char *name)
{
- RAII_VAR(struct ast_sip_sched_task *, schtd, NULL, ao2_cleanup);
+ int is_running;
+ struct ast_sip_sched_task *schtd;
if (ast_strlen_zero(name)) {
return 0;
}
- schtd = ao2_find(tasks, name, OBJ_SEARCH_KEY | OBJ_NOLOCK);
+ schtd = ao2_find(tasks, name, OBJ_SEARCH_KEY);
if (!schtd) {
return 0;
}
- return schtd->is_running;
+ is_running = schtd->is_running;
+ ao2_ref(schtd, -1);
+ return is_running;
}
-static void schtd_destructor(void *data)
+static void schtd_dtor(void *data)
{
struct ast_sip_sched_task *schtd = data;
+ if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+ ast_log(LOG_DEBUG, "Sched %p: Destructor %s\n", schtd, schtd->name);
+ }
if (schtd->flags & AST_SIP_SCHED_TASK_DATA_AO2) {
/* release our own ref, then release the callers if asked to do so */
ao2_ref(schtd->task_data, (schtd->flags & AST_SIP_SCHED_TASK_DATA_FREE) ? -2 : -1);
} else if (schtd->task_data && (schtd->flags & AST_SIP_SCHED_TASK_DATA_FREE)) {
ast_free(schtd->task_data);
}
+ ast_taskprocessor_unreference(schtd->serializer);
}
struct ast_sip_sched_task *ast_sip_schedule_task(struct ast_taskprocessor *serializer,
- int interval, ast_sip_task sip_task, char *name, void *task_data, enum ast_sip_scheduler_task_flags flags)
+ int interval, ast_sip_task sip_task, const char *name, void *task_data,
+ enum ast_sip_scheduler_task_flags flags)
{
#define ID_LEN 13 /* task_deadbeef */
struct ast_sip_sched_task *schtd;
int res;
- if (interval < 0) {
+ if (interval <= 0) {
return NULL;
}
- schtd = ao2_alloc((sizeof(*schtd) + (!ast_strlen_zero(name) ? strlen(name) : ID_LEN) + 1), schtd_destructor);
+ schtd = ao2_alloc((sizeof(*schtd) + (!ast_strlen_zero(name) ? strlen(name) : ID_LEN) + 1),
+ schtd_dtor);
if (!schtd) {
return NULL;
}
- schtd->task_id = ast_atomic_fetchadd_int(&task_count, 1);
- schtd->serializer = serializer;
+ schtd->serializer = ao2_bump(serializer);
+ schtd->task_data = task_data;
schtd->task = sip_task;
+ schtd->interval = interval;
+ schtd->flags = flags;
if (!ast_strlen_zero(name)) {
strcpy(schtd->name, name); /* Safe */
} else {
- sprintf(schtd->name, "task_%08x", schtd->task_id);
+ uint32_t task_id;
+
+ task_id = ast_atomic_fetchadd_int(&task_count, 1);
+ sprintf(schtd->name, "task_%08x", task_id);
+ }
+ if (schtd->flags & AST_SIP_SCHED_TASK_TRACK) {
+ ast_log(LOG_DEBUG, "Sched %p: Scheduling %s for %d ms\n", schtd, schtd->name,
+ interval);
}
- schtd->task_data = task_data;
- schtd->flags = flags;
- schtd->interval = interval;
schtd->when_queued = ast_tvnow();
+ if (!(schtd->flags & AST_SIP_SCHED_TASK_DELAY)) {
+ schtd->next_periodic = ast_tvadd(schtd->when_queued,
+ ast_samp2tv(schtd->interval, 1000));
+ }
if (flags & AST_SIP_SCHED_TASK_DATA_AO2) {
ao2_ref(task_data, +1);
}
- res = ast_sched_add(scheduler_context, interval, push_to_serializer, (const void *)schtd);
+
+ /*
+ * We must put it in the 'tasks' container before scheduling
+ * the task because we don't want the push_to_serializer()
+ * sched task to "remove" it on failure before we even put
+ * it in. If this happens then nothing would remove it from
+ * the 'tasks' container.
+ */
+ ao2_link(tasks, schtd);
+
+ /*
+ * Lock so we are guaranteed to get the sched id set before
+ * the push_to_serializer() sched task can clear it.
+ */
+ ao2_lock(schtd);
+ res = ast_sched_add(scheduler_context, interval, push_to_serializer, schtd);
+ schtd->current_scheduler_id = res;
+ ao2_unlock(schtd);
if (res < 0) {
+ ao2_unlink(tasks, schtd);
ao2_ref(schtd, -1);
return NULL;
- } else {
- schtd->current_scheduler_id = res;
- ao2_link(tasks, schtd);
}
return schtd;
@@ -367,16 +447,17 @@ struct ast_sip_sched_task *ast_sip_schedule_task(struct ast_taskprocessor *seria
static char *cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- struct ao2_iterator i;
+ struct ao2_iterator iter;
+ struct ao2_container *sorted_tasks;
struct ast_sip_sched_task *schtd;
- const char *log_format = ast_logger_get_dateformat();
+ const char *log_format;
struct ast_tm tm;
char queued[32];
char last_start[32];
char next_start[32];
int datelen;
- struct timeval now = ast_tvnow();
- const char *separator = "======================================";
+ struct timeval now;
+ static const char separator[] = "=============================================";
switch (cmd) {
case CLI_INIT:
@@ -392,26 +473,47 @@ static char *cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
return CLI_SHOWUSAGE;
}
+ /* Get a sorted snapshot of the scheduled tasks */
+ sorted_tasks = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_NOLOCK, 0,
+ ast_sip_sched_task_sort_fn, NULL);
+ if (!sorted_tasks) {
+ return CLI_SUCCESS;
+ }
+ if (ao2_container_dup(sorted_tasks, tasks, 0)) {
+ ao2_ref(sorted_tasks, -1);
+ return CLI_SUCCESS;
+ }
+
+ now = ast_tvnow();
+ log_format = ast_logger_get_dateformat();
+
ast_localtime(&now, &tm, NULL);
datelen = ast_strftime(queued, sizeof(queued), log_format, &tm);
ast_cli(a->fd, "PJSIP Scheduled Tasks:\n\n");
- ast_cli(a->fd, " %1$-24s %2$-9s %3$-9s %4$-5s %6$-*5$s %7$-*5$s %8$-*5$s %9$7s\n",
+ ast_cli(a->fd, "%1$-45s %2$-9s %3$-9s %4$-5s %6$-*5$s %7$-*5$s %8$-*5$s %9$7s\n",
"Task Name", "Interval", "Times Run", "State",
datelen, "Queued", "Last Started", "Next Start", "( secs)");
- ast_cli(a->fd, " %1$-24.24s %2$-9.9s %3$-9.9s %4$-5.5s %6$-*5$.*5$s %7$-*5$.*5$s %9$-*8$.*8$s\n",
+ ast_cli(a->fd, "%1$-45.45s %2$-9.9s %3$-9.9s %4$-5.5s %6$-*5$.*5$s %7$-*5$.*5$s %9$-*8$.*8$s\n",
separator, separator, separator, separator,
datelen, separator, separator, datelen + 8, separator);
+ iter = ao2_iterator_init(sorted_tasks, AO2_ITERATOR_UNLINK);
+ for (; (schtd = ao2_iterator_next(&iter)); ao2_ref(schtd, -1)) {
+ int next_run_sec;
+ struct timeval next;
+
+ ao2_lock(schtd);
- ao2_ref(tasks, +1);
- ao2_rdlock(tasks);
- i = ao2_iterator_init(tasks, 0);
- while ((schtd = ao2_iterator_next(&i))) {
- int next_run_sec = ast_sip_sched_task_get_next_run(schtd) / 1000;
- struct timeval next = ast_tvadd(now, (struct timeval) {next_run_sec, 0});
+ next_run_sec = ast_sip_sched_task_get_next_run(schtd) / 1000;
+ if (next_run_sec < 0) {
+ /* Scheduled task is now canceled */
+ ao2_unlock(schtd);
+ continue;
+ }
+ next = ast_tvadd(now, ast_tv(next_run_sec, 0));
ast_localtime(&schtd->when_queued, &tm, NULL);
ast_strftime(queued, sizeof(queued), log_format, &tm);
@@ -426,7 +528,7 @@ static char *cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
ast_localtime(&next, &tm, NULL);
ast_strftime(next_start, sizeof(next_start), log_format, &tm);
- ast_cli(a->fd, " %1$-24.24s %2$9.3f %3$9d %4$-5s %6$-*5$s %7$-*5$s %8$-*5$s (%9$5d)\n",
+ ast_cli(a->fd, "%1$-46.46s%2$9.3f %3$9d %4$-5s %6$-*5$s %7$-*5$s %8$-*5$s (%9$5d)\n",
schtd->name,
schtd->interval / 1000.0,
schtd->run_count,
@@ -434,11 +536,10 @@ static char *cli_show_tasks(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
datelen, queued, last_start,
next_start,
next_run_sec);
- ao2_cleanup(schtd);
+ ao2_unlock(schtd);
}
- ao2_iterator_destroy(&i);
- ao2_unlock(tasks);
- ao2_ref(tasks, -1);
+ ao2_iterator_destroy(&iter);
+ ao2_ref(sorted_tasks, -1);
ast_cli(a->fd, "\n");
return CLI_SUCCESS;
@@ -450,7 +551,8 @@ static struct ast_cli_entry cli_commands[] = {
int ast_sip_initialize_scheduler(void)
{
- if (!(scheduler_context = ast_sched_context_create())) {
+ scheduler_context = ast_sched_context_create();
+ if (!scheduler_context) {
ast_log(LOG_ERROR, "Failed to create scheduler. Aborting load\n");
return -1;
}
@@ -461,8 +563,9 @@ int ast_sip_initialize_scheduler(void)
return -1;
}
- tasks = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT,
- TASK_BUCKETS, ast_sip_sched_task_hash_fn, ast_sip_sched_task_sort_fn, ast_sip_sched_task_cmp_fn);
+ tasks = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK,
+ AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, TASK_BUCKETS, ast_sip_sched_task_hash_fn,
+ ast_sip_sched_task_sort_fn, ast_sip_sched_task_cmp_fn);
if (!tasks) {
ast_log(LOG_ERROR, "Failed to allocate task container. Aborting load\n");
ast_sched_context_destroy(scheduler_context);
@@ -479,7 +582,21 @@ int ast_sip_destroy_scheduler(void)
ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
if (scheduler_context) {
+ if (tasks) {
+ struct ao2_iterator iter;
+ struct ast_sip_sched_task *schtd;
+
+ /* Cancel all scheduled tasks */
+ iter = ao2_iterator_init(tasks, 0);
+ while ((schtd = ao2_iterator_next(&iter))) {
+ ast_sip_sched_task_cancel(schtd);
+ ao2_ref(schtd, -1);
+ }
+ ao2_iterator_destroy(&iter);
+ }
+
ast_sched_context_destroy(scheduler_context);
+ scheduler_context = NULL;
}
ao2_cleanup(tasks);
diff --git a/res/res_pjsip_header_funcs.c b/res/res_pjsip_header_funcs.c
index 6c0f9151d..798a1cde6 100644
--- a/res/res_pjsip_header_funcs.c
+++ b/res/res_pjsip_header_funcs.c
@@ -153,7 +153,7 @@ static const struct ast_datastore_info header_datastore = {
.type = "header_datastore",
};
-/*! \brief Data structure used for ast_sip_push_task_synchronous */
+/*! \brief Data structure used for ast_sip_push_task_wait_serializer */
struct header_data {
struct ast_sip_channel_pvt *channel;
char *header_name;
@@ -480,11 +480,11 @@ static int func_read_header(struct ast_channel *chan, const char *function, char
header_data.len = len;
if (!strcasecmp(args.action, "read")) {
- return ast_sip_push_task_synchronous(channel->session->serializer, read_header,
- &header_data);
+ return ast_sip_push_task_wait_serializer(channel->session->serializer,
+ read_header, &header_data);
} else if (!strcasecmp(args.action, "remove")) {
- return ast_sip_push_task_synchronous(channel->session->serializer, remove_header,
- &header_data);
+ return ast_sip_push_task_wait_serializer(channel->session->serializer,
+ remove_header, &header_data);
} else {
ast_log(AST_LOG_ERROR,
"Unknown action '%s' is not valid, must be 'read' or 'remove'.\n",
@@ -539,14 +539,14 @@ static int func_write_header(struct ast_channel *chan, const char *cmd, char *da
header_data.len = 0;
if (!strcasecmp(args.action, "add")) {
- return ast_sip_push_task_synchronous(channel->session->serializer, add_header,
- &header_data);
+ return ast_sip_push_task_wait_serializer(channel->session->serializer,
+ add_header, &header_data);
} else if (!strcasecmp(args.action, "update")) {
- return ast_sip_push_task_synchronous(channel->session->serializer, update_header,
- &header_data);
+ return ast_sip_push_task_wait_serializer(channel->session->serializer,
+ update_header, &header_data);
} else if (!strcasecmp(args.action, "remove")) {
- return ast_sip_push_task_synchronous(channel->session->serializer, remove_header,
- &header_data);
+ return ast_sip_push_task_wait_serializer(channel->session->serializer,
+ remove_header, &header_data);
} else {
ast_log(AST_LOG_ERROR,
"Unknown action '%s' is not valid, must be 'add', 'update', or 'remove'.\n",
diff --git a/res/res_pjsip_history.c b/res/res_pjsip_history.c
index ab035a296..eed06eed8 100644
--- a/res/res_pjsip_history.c
+++ b/res/res_pjsip_history.c
@@ -1385,7 +1385,7 @@ static int unload_module(void)
ast_cli_unregister_multiple(cli_pjsip, ARRAY_LEN(cli_pjsip));
ast_sip_unregister_service(&logging_module);
- ast_sip_push_task_synchronous(NULL, clear_history_entries, NULL);
+ ast_sip_push_task_wait_servant(NULL, clear_history_entries, NULL);
AST_VECTOR_FREE(&vector_history);
ast_pjproject_caching_pool_destroy(&cachingpool);
diff --git a/res/res_pjsip_notify.c b/res/res_pjsip_notify.c
index 253cf9ac8..98a75c964 100644
--- a/res/res_pjsip_notify.c
+++ b/res/res_pjsip_notify.c
@@ -25,6 +25,7 @@
#include "asterisk.h"
#include <pjsip.h>
+#include <pjsip_ua.h>
#include "asterisk/cli.h"
#include "asterisk/config.h"
@@ -32,12 +33,13 @@
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/res_pjsip.h"
+#include "asterisk/res_pjsip_session.h"
#include "asterisk/sorcery.h"
/*** DOCUMENTATION
<manager name="PJSIPNotify" language="en_US">
<synopsis>
- Send a NOTIFY to either an endpoint or an arbitrary URI.
+ Send a NOTIFY to either an endpoint, an arbitrary URI, or inside a SIP dialog.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
@@ -47,6 +49,9 @@
<parameter name="URI" required="false">
<para>Abritrary URI to which to send the NOTIFY.</para>
</parameter>
+ <parameter name="channel" required="false">
+ <para>Channel name to send the NOTIFY. Must be a PJSIP channel.</para>
+ </parameter>
<parameter name="Variable" required="true">
<para>Appends variables as headers/content to the NOTIFY. If the variable is
named <literal>Content</literal>, then the value will compose the body
@@ -55,14 +60,14 @@
</parameter>
</syntax>
<description>
- <para>Sends a NOTIFY to an endpoint or an arbitrary URI.</para>
+ <para>Sends a NOTIFY to an endpoint, an arbitrary URI, or inside a SIP dialog.</para>
<para>All parameters for this event must be specified in the body of this
request via multiple <literal>Variable: name=value</literal> sequences.</para>
- <note><para>One (and only one) of <literal>Endpoint</literal> or
- <literal>URI</literal> must be specified. If <literal>URI</literal> is used,
- the default outbound endpoint will be used to send the message. If the default
- outbound endpoint isn't configured, this command can not send to an arbitrary
- URI.</para></note>
+ <note><para>One (and only one) of <literal>Endpoint</literal>,
+ <literal>URI</literal>, or <literal>Channel</literal> must be specified.
+ If <literal>URI</literal> is used, the default outbound endpoint will be used
+ to send the message. If the default outbound endpoint isn't configured, this command
+ can not send to an arbitrary URI.</para></note>
</description>
</manager>
<configInfo name="res_pjsip_notify" language="en_US">
@@ -289,6 +294,16 @@ struct notify_uri_data {
void (*build_notify)(pjsip_tx_data *, void *);
};
+/*!
+ * \internal
+ * \brief Structure to hold task data for notifications (channel variant)
+ */
+struct notify_channel_data {
+ struct ast_sip_session *session;
+ void *info;
+ void (*build_notify)(pjsip_tx_data *, void *);
+};
+
static void notify_cli_uri_data_destroy(void *obj)
{
struct notify_uri_data *data = obj;
@@ -381,6 +396,19 @@ static void notify_ami_uri_data_destroy(void *obj)
ast_variables_destroy(info);
}
+/*!
+ * \internal
+ * \brief Destroy the notify AMI channel data releasing any resources.
+ */
+static void notify_ami_channel_data_destroy(void *obj)
+{
+ struct notify_channel_data *data = obj;
+ struct ast_variable *info = data->info;
+
+ ao2_cleanup(data->session);
+ ast_variables_destroy(info);
+}
+
static void build_ami_notify(pjsip_tx_data *tdata, void *info);
/*!
@@ -432,6 +460,28 @@ static struct notify_uri_data* notify_ami_uri_data_create(
/*!
* \internal
+ * \brief Construct a notify channel data object for AMI.
+ */
+static struct notify_channel_data *notify_ami_channel_data_create(
+ struct ast_sip_session *session, void *info)
+{
+ struct notify_channel_data *data;
+
+ data = ao2_alloc_options(sizeof(*data), notify_ami_channel_data_destroy,
+ AO2_ALLOC_OPT_LOCK_NOLOCK);
+ if (!data) {
+ return NULL;
+ }
+
+ data->session = session;
+ data->info = info;
+ data->build_notify = build_ami_notify;
+
+ return data;
+}
+
+/*!
+ * \internal
* \brief Checks if the given header name is not allowed.
*
* \details Some headers are not allowed to be set by the user within the
@@ -672,9 +722,45 @@ static int notify_uri(void *obj)
return 0;
}
+/*!
+ * \internal
+ * \brief Send a notify request to a channel.
+ */
+static int notify_channel(void *obj)
+{
+ RAII_VAR(struct notify_channel_data *, data, obj, ao2_cleanup);
+ pjsip_tx_data *tdata;
+ struct pjsip_dialog *dlg;
+
+ if (!data->session->channel
+ || !data->session->inv_session
+ || data->session->inv_session->state < PJSIP_INV_STATE_EARLY
+ || data->session->inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
+ return -1;
+ }
+
+ ast_debug(1, "Sending notify on channel %s\n", ast_channel_name(data->session->channel));
+
+ dlg = data->session->inv_session->dlg;
+
+ if (ast_sip_create_request("NOTIFY", dlg, NULL, NULL, NULL, &tdata)) {
+ return -1;
+ }
+
+ ast_sip_add_header(tdata, "Subscription-State", "terminated");
+ data->build_notify(tdata, data->info);
+
+ if (ast_sip_send_request(tdata, dlg, NULL, NULL, NULL)) {
+ return -1;
+ }
+
+ return 0;
+}
+
enum notify_result {
SUCCESS,
INVALID_ENDPOINT,
+ INVALID_CHANNEL,
ALLOC_ERROR,
TASK_PUSH_ERROR
};
@@ -684,6 +770,10 @@ typedef struct notify_data *(*task_data_create)(
typedef struct notify_uri_data *(*task_uri_data_create)(
const char *uri, void *info);
+
+typedef struct notify_channel_data *(*task_channel_data_create)(
+ struct ast_sip_session *session, void *info);
+
/*!
* \internal
* \brief Send a NOTIFY request to the endpoint within a threaded task.
@@ -734,6 +824,68 @@ static enum notify_result push_notify_uri(const char *uri, void *info,
/*!
* \internal
+ * \brief Send a NOTIFY request in a channel within an threaded task.
+ */
+static enum notify_result push_notify_channel(const char *channel_name, void *info,
+ task_channel_data_create data_create)
+{
+ struct notify_channel_data *data;
+ struct ast_channel *ch;
+ struct ast_sip_session *session;
+ struct ast_sip_channel_pvt *ch_pvt;
+
+ /* note: this increases the refcount of the channel */
+ ch = ast_channel_get_by_name(channel_name);
+ if (!ch) {
+ ast_debug(1, "No channel found with name %s", channel_name);
+ return INVALID_CHANNEL;
+ }
+
+ if (strcmp(ast_channel_tech(ch)->type, "PJSIP")) {
+ ast_log(LOG_WARNING, "Channel was a non-PJSIP channel: %s\n", channel_name);
+ ast_channel_unref(ch);
+ return INVALID_CHANNEL;
+ }
+
+ ast_channel_lock(ch);
+ ch_pvt = ast_channel_tech_pvt(ch);
+ session = ch_pvt->session;
+
+ if (!session || !session->inv_session
+ || session->inv_session->state < PJSIP_INV_STATE_EARLY
+ || session->inv_session->state == PJSIP_INV_STATE_DISCONNECTED) {
+ ast_debug(1, "No active session for channel %s\n", channel_name);
+ ast_channel_unlock(ch);
+ ast_channel_unref(ch);
+ return INVALID_CHANNEL;
+ }
+
+ ao2_ref(session, +1);
+ ast_channel_unlock(ch);
+
+ /* don't keep a reference to the channel, we've got a reference to the session */
+ ast_channel_unref(ch);
+
+ /*
+ * data_create will take ownership of the session,
+ * and take care of releasing the ref.
+ */
+ data = data_create(session, info);
+ if (!data) {
+ ao2_ref(session, -1);
+ return ALLOC_ERROR;
+ }
+
+ if (ast_sip_push_task(session->serializer, notify_channel, data)) {
+ ao2_ref(data, -1);
+ return TASK_PUSH_ERROR;
+ }
+
+ return SUCCESS;
+}
+
+/*!
+ * \internal
* \brief Do completion on the endpoint.
*/
static char *cli_complete_endpoint(const char *word, int state)
@@ -915,6 +1067,10 @@ static void manager_notify_endpoint(struct mansession *s,
}
switch (push_notify(endpoint_name, vars, notify_ami_data_create)) {
+ case INVALID_CHANNEL:
+ /* Shouldn't be possible. */
+ ast_assert(0);
+ break;
case INVALID_ENDPOINT:
ast_variables_destroy(vars);
astman_send_error_va(s, m, "Unable to retrieve endpoint %s",
@@ -944,6 +1100,10 @@ static void manager_notify_uri(struct mansession *s,
struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL);
switch (push_notify_uri(uri, vars, notify_ami_uri_data_create)) {
+ case INVALID_CHANNEL:
+ /* Shouldn't be possible. */
+ ast_assert(0);
+ break;
case INVALID_ENDPOINT:
/* Shouldn't be possible. */
ast_assert(0);
@@ -964,22 +1124,70 @@ static void manager_notify_uri(struct mansession *s,
/*!
* \internal
+ * \brief Completes SIPNotify AMI command in channel mode.
+ */
+static void manager_notify_channel(struct mansession *s,
+ const struct message *m, const char *channel)
+{
+ struct ast_variable *vars = astman_get_variables_order(m, ORDER_NATURAL);
+
+ switch (push_notify_channel(channel, vars, notify_ami_channel_data_create)) {
+ case INVALID_CHANNEL:
+ ast_variables_destroy(vars);
+ astman_send_error(s, m, "Channel not found");
+ break;
+ case INVALID_ENDPOINT:
+ /* Shouldn't be possible. */
+ ast_assert(0);
+ break;
+ case ALLOC_ERROR:
+ ast_variables_destroy(vars);
+ astman_send_error(s, m, "Unable to allocate NOTIFY task data");
+ break;
+ case TASK_PUSH_ERROR:
+ /* Don't need to destroy vars since it is handled by cleanup in push_notify_channel */
+ astman_send_error(s, m, "Unable to push Notify task");
+ break;
+ case SUCCESS:
+ astman_send_ack(s, m, "NOTIFY sent");
+ break;
+ }
+}
+
+/*!
+ * \internal
* \brief AMI entry point to send a SIP notify to an endpoint.
*/
static int manager_notify(struct mansession *s, const struct message *m)
{
const char *endpoint_name = astman_get_header(m, "Endpoint");
const char *uri = astman_get_header(m, "URI");
+ const char *channel = astman_get_header(m, "Channel");
+ int count = 0;
+
+ if (!ast_strlen_zero(endpoint_name)) {
+ ++count;
+ }
+ if (!ast_strlen_zero(uri)) {
+ ++count;
+ }
+ if (!ast_strlen_zero(channel)) {
+ ++count;
+ }
- if (!ast_strlen_zero(endpoint_name) && !ast_strlen_zero(uri)) {
- astman_send_error(s, m, "PJSIPNotify action can not handle a request specifying "
- "both 'URI' and 'Endpoint'. You must use only one of the two.\n");
+ if (1 < count) {
+ astman_send_error(s, m,
+ "PJSIPNotify requires either an endpoint name, a SIP URI, or a channel. "
+ "You must use only one of them.");
} else if (!ast_strlen_zero(endpoint_name)) {
manager_notify_endpoint(s, m, endpoint_name);
} else if (!ast_strlen_zero(uri)) {
manager_notify_uri(s, m, uri);
+ } else if (!ast_strlen_zero(channel)) {
+ manager_notify_channel(s, m, channel);
} else {
- astman_send_error(s, m, "PJSIPNotify requires either an endpoint name or a SIP URI.");
+ astman_send_error(s, m,
+ "PJSIPNotify requires either an endpoint name, a SIP URI, or a channel.");
}
return 0;
diff --git a/res/res_pjsip_outbound_publish.c b/res/res_pjsip_outbound_publish.c
index 8befbc1e8..4894e55d1 100644
--- a/res/res_pjsip_outbound_publish.c
+++ b/res/res_pjsip_outbound_publish.c
@@ -1070,7 +1070,7 @@ static struct sip_outbound_publisher *sip_outbound_publisher_alloc(
return NULL;
}
- if (ast_sip_push_task_synchronous(NULL, sip_outbound_publisher_init, publisher)) {
+ if (ast_sip_push_task_wait_servant(NULL, sip_outbound_publisher_init, publisher)) {
ast_log(LOG_ERROR, "Unable to create publisher for outbound publish '%s'\n",
ast_sorcery_object_get_id(client->publish));
ao2_ref(publisher, -1);
@@ -1514,8 +1514,8 @@ static int current_state_reusable(struct ast_sip_outbound_publish *publish,
*/
old_publish = current_state->client->publish;
current_state->client->publish = publish;
- if (ast_sip_push_task_synchronous(
- NULL, sip_outbound_publisher_reinit_all, current_state->client->publishers)) {
+ if (ast_sip_push_task_wait_servant(NULL, sip_outbound_publisher_reinit_all,
+ current_state->client->publishers)) {
/*
* If the state object fails to re-initialize then swap
* the old publish info back in.
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index 2839ecbab..0d815ad39 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -834,6 +834,8 @@ static int reregister_immediately_cb(void *obj)
*
* \param obj What is needed to initiate a reregister attempt.
*
+ * \note Normally executed by the pjsip monitor thread.
+ *
* \return Nothing
*/
static void registration_transport_shutdown_cb(void *obj)
@@ -1480,7 +1482,7 @@ static int sip_outbound_registration_apply(const struct ast_sorcery *sorcery, vo
return -1;
}
- if (ast_sip_push_task_synchronous(new_state->client_state->serializer,
+ if (ast_sip_push_task_wait_serializer(new_state->client_state->serializer,
sip_outbound_registration_regc_alloc, new_state)) {
return -1;
}
@@ -1850,8 +1852,7 @@ static int ami_outbound_registration_detail(void *obj, void *arg, int flags)
struct sip_ami_outbound *ami = arg;
ami->registration = obj;
- return ast_sip_push_task_synchronous(
- NULL, ami_outbound_registration_task, ami);
+ return ast_sip_push_task_wait_servant(NULL, ami_outbound_registration_task, ami);
}
static int ami_show_outbound_registrations(struct mansession *s,
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index 69c256dab..d98491495 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -560,15 +560,52 @@ static void *publication_resource_alloc(const char *name)
return ast_sorcery_generic_alloc(sizeof(struct ast_sip_publication_resource), publication_resource_destroy);
}
-static void sub_tree_transport_cb(void *data) {
+static int sub_tree_subscription_terminate_cb(void *data)
+{
struct sip_subscription_tree *sub_tree = data;
- ast_debug(3, "Transport destroyed. Removing subscription '%s->%s' prune on restart: %d\n",
+ if (!sub_tree->evsub) {
+ /* Something else already terminated the subscription. */
+ ao2_ref(sub_tree, -1);
+ return 0;
+ }
+
+ ast_debug(3, "Transport destroyed. Removing subscription '%s->%s' prune on boot: %d\n",
sub_tree->persistence->endpoint, sub_tree->root->resource,
sub_tree->persistence->prune_on_boot);
sub_tree->state = SIP_SUB_TREE_TERMINATE_IN_PROGRESS;
pjsip_evsub_terminate(sub_tree->evsub, PJ_TRUE);
+
+ ao2_ref(sub_tree, -1);
+ return 0;
+}
+
+/*!
+ * \internal
+ * \brief The reliable transport we used as a subscription contact has shutdown.
+ *
+ * \param data What subscription needs to be terminated.
+ *
+ * \note Normally executed by the pjsip monitor thread.
+ *
+ * \return Nothing
+ */
+static void sub_tree_transport_cb(void *data)
+{
+ struct sip_subscription_tree *sub_tree = data;
+
+ /*
+ * Push off the subscription termination to the serializer to
+ * avoid deadlock. Another thread could be trying to send a
+ * message on the subscription that can deadlock with this
+ * thread.
+ */
+ ao2_ref(sub_tree, +1);
+ if (ast_sip_push_task(sub_tree->serializer, sub_tree_subscription_terminate_cb,
+ sub_tree)) {
+ ao2_ref(sub_tree, -1);
+ }
}
/*! \brief Destructor for subscription persistence */
@@ -621,7 +658,7 @@ static void subscription_persistence_update(struct sip_subscription_tree *sub_tr
return;
}
- ast_debug(3, "Updating persistence for '%s->%s' prune on restart: %s\n",
+ ast_debug(3, "Updating persistence for '%s->%s' prune on boot: %s\n",
sub_tree->persistence->endpoint, sub_tree->root->resource,
sub_tree->persistence->prune_on_boot ? "yes" : "no");
@@ -645,7 +682,7 @@ static void subscription_persistence_update(struct sip_subscription_tree *sub_tr
sub_tree->endpoint, rdata);
if (sub_tree->persistence->prune_on_boot) {
- ast_debug(3, "adding transport monitor on %s for '%s->%s' prune on restart: %d\n",
+ ast_debug(3, "adding transport monitor on %s for '%s->%s' prune on boot: %d\n",
rdata->tp_info.transport->obj_name,
sub_tree->persistence->endpoint, sub_tree->root->resource,
sub_tree->persistence->prune_on_boot);
@@ -1318,7 +1355,8 @@ static void subscription_tree_destructor(void *obj)
destroy_subscriptions(sub_tree->root);
if (sub_tree->dlg) {
- ast_sip_push_task_synchronous(sub_tree->serializer, subscription_unreference_dialog, sub_tree);
+ ast_sip_push_task_wait_servant(sub_tree->serializer,
+ subscription_unreference_dialog, sub_tree);
}
ao2_cleanup(sub_tree->endpoint);
@@ -1665,7 +1703,8 @@ static int subscription_persistence_recreate(void *obj, void *arg, int flags)
}
recreate_data.persistence = persistence;
recreate_data.rdata = &rdata;
- if (ast_sip_push_task_synchronous(serializer, sub_persistence_recreate, &recreate_data)) {
+ if (ast_sip_push_task_wait_serializer(serializer, sub_persistence_recreate,
+ &recreate_data)) {
ast_log(LOG_WARNING, "Failed recreating '%s' subscription: Could not continue under distributor serializer.\n",
persistence->endpoint);
ast_sorcery_delete(ast_sip_get_sorcery(), persistence);
diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c
index 7d892f653..1e6ca7f46 100644
--- a/res/res_pjsip_refer.c
+++ b/res/res_pjsip_refer.c
@@ -316,7 +316,15 @@ static void refer_progress_on_evsub_state(pjsip_evsub *sub, pjsip_event *event)
/* It's possible that a task is waiting to remove us already, so bump the refcount of progress so it doesn't get destroyed */
ao2_ref(progress, +1);
pjsip_dlg_dec_lock(progress->dlg);
- ast_sip_push_task_synchronous(progress->serializer, refer_progress_terminate, progress);
+ /*
+ * XXX We are always going to execute this inline rather than
+ * in the serializer because this function is a PJPROJECT
+ * callback and thus has to be a SIP servant thread.
+ *
+ * The likely remedy is to push most of this function into
+ * refer_progress_terminate() with ast_sip_push_task().
+ */
+ ast_sip_push_task_wait_servant(progress->serializer, refer_progress_terminate, progress);
pjsip_dlg_inc_lock(progress->dlg);
ao2_ref(progress, -1);
@@ -917,10 +925,7 @@ static int invite_replaces(void *data)
ast_channel_ref(invite->session->channel);
invite->channel = invite->session->channel;
- ast_channel_lock(invite->channel);
- invite->bridge = ast_channel_get_bridge(invite->channel);
- ast_channel_unlock(invite->channel);
-
+ invite->bridge = ast_bridge_transfer_acquire_bridge(invite->channel);
return 0;
}
@@ -963,7 +968,8 @@ static int refer_incoming_invite_request(struct ast_sip_session *session, struct
invite.session = other_session;
- if (ast_sip_push_task_synchronous(other_session->serializer, invite_replaces, &invite)) {
+ if (ast_sip_push_task_wait_serializer(other_session->serializer, invite_replaces,
+ &invite)) {
response = 481;
goto inv_replace_failed;
}
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index bdee91fb3..985933e2d 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -337,7 +337,7 @@ static int contact_transport_monitor_matcher(void *a, void *b)
&& strcmp(ma->contact_name, mb->contact_name) == 0;
}
-static void register_contact_transport_shutdown_cb(void *data)
+static int register_contact_transport_remove_cb(void *data)
{
struct contact_transport_monitor *monitor = data;
struct ast_sip_contact *contact;
@@ -345,7 +345,8 @@ static void register_contact_transport_shutdown_cb(void *data)
aor = ast_sip_location_retrieve_aor(monitor->aor_name);
if (!aor) {
- return;
+ ao2_ref(monitor, -1);
+ return 0;
}
ao2_lock(aor);
@@ -365,6 +366,35 @@ static void register_contact_transport_shutdown_cb(void *data)
}
ao2_unlock(aor);
ao2_ref(aor, -1);
+
+ ao2_ref(monitor, -1);
+ return 0;
+}
+
+/*!
+ * \internal
+ * \brief The reliable transport we registered as a contact has shutdown.
+ *
+ * \param data What contact needs to be removed.
+ *
+ * \note Normally executed by the pjsip monitor thread.
+ *
+ * \return Nothing
+ */
+static void register_contact_transport_shutdown_cb(void *data)
+{
+ struct contact_transport_monitor *monitor = data;
+
+ /*
+ * Push off to a default serializer. This is in case sorcery
+ * does database accesses for contacts. Database accesses may
+ * not be on this machine. We don't want to tie up the pjsip
+ * monitor thread with potentially long access times.
+ */
+ ao2_ref(monitor, +1);
+ if (ast_sip_push_task(NULL, register_contact_transport_remove_cb, monitor)) {
+ ao2_ref(monitor, -1);
+ }
}
AST_VECTOR(excess_contact_vector, struct ast_sip_contact *);
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index 03d37652f..14ed3b186 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -1096,6 +1096,9 @@ static void add_rtcp_fb_to_stream(struct ast_sip_session *session,
attr = pjmedia_sdp_attr_create(pool, "rtcp-fb", pj_cstr(&stmp, "* goog-remb"));
pjmedia_sdp_attr_add(&media->attr_count, media->attr, attr);
+
+ attr = pjmedia_sdp_attr_create(pool, "rtcp-fb", pj_cstr(&stmp, "* nack"));
+ pjmedia_sdp_attr_add(&media->attr_count, media->attr, attr);
}
/*! \brief Function which negotiates an incoming media stream */
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index d13b372be..49ab87568 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -4153,7 +4153,7 @@ static void session_outgoing_nat_hook(pjsip_tx_data *tdata, struct ast_sip_trans
if (ast_sip_transport_is_local(transport_state, &our_sdp_addr) || !transport_state->localnet) {
ast_debug(5, "Setting external media address to %s\n", ast_sockaddr_stringify_host(&transport_state->external_media_address));
pj_strdup2(tdata->pool, &sdp->conn->addr, ast_sockaddr_stringify_host(&transport_state->external_media_address));
- pj_strdup2(tdata->pool, &sdp->origin.addr, transport->external_media_address);
+ pj_strassign(&sdp->origin.addr, &sdp->conn->addr);
}
}
diff --git a/res/res_pjsip_transport_websocket.c b/res/res_pjsip_transport_websocket.c
index 974b15087..633594359 100644
--- a/res/res_pjsip_transport_websocket.c
+++ b/res/res_pjsip_transport_websocket.c
@@ -377,7 +377,7 @@ static void websocket_cb(struct ast_websocket *session, struct ast_variable *par
create_data.ws_session = session;
- if (ast_sip_push_task_synchronous(serializer, transport_create, &create_data)) {
+ if (ast_sip_push_task_wait_serializer(serializer, transport_create, &create_data)) {
ast_log(LOG_ERROR, "Could not create WebSocket transport.\n");
ast_taskprocessor_unreference(serializer);
ast_websocket_unref(session);
@@ -396,13 +396,13 @@ static void websocket_cb(struct ast_websocket *session, struct ast_variable *par
}
if (opcode == AST_WEBSOCKET_OPCODE_TEXT || opcode == AST_WEBSOCKET_OPCODE_BINARY) {
- ast_sip_push_task_synchronous(serializer, transport_read, &read_data);
+ ast_sip_push_task_wait_serializer(serializer, transport_read, &read_data);
} else if (opcode == AST_WEBSOCKET_OPCODE_CLOSE) {
break;
}
}
- ast_sip_push_task_synchronous(serializer, transport_shutdown, transport);
+ ast_sip_push_task_wait_serializer(serializer, transport_shutdown, transport);
ast_taskprocessor_unreference(serializer);
ast_websocket_unref(session);
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index c88903777..4ac20d551 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -71,6 +71,7 @@
#include "asterisk/smoother.h"
#include "asterisk/uuid.h"
#include "asterisk/test.h"
+#include "asterisk/data_buffer.h"
#ifdef HAVE_PJPROJECT
#include "asterisk/res_pjproject.h"
#endif
@@ -92,6 +93,8 @@
#define TURN_STATE_WAIT_TIME 2000
+#define DEFAULT_RTP_BUFFER_SIZE 250
+
/*! Full INTRA-frame Request / Fast Update Request (From RFC2032) */
#define RTCP_PT_FUR 192
/*! Sender Report (From RFC3550) */
@@ -373,6 +376,8 @@ struct ast_rtp {
struct rtp_red *red;
+ struct ast_data_buffer *send_buffer; /*!< Buffer for storing sent packets for retransmission */
+
#ifdef HAVE_PJPROJECT
ast_cond_t cond; /*!< ICE/TURN condition for signaling */
@@ -509,6 +514,12 @@ struct rtp_red {
long int prev_ts;
};
+/*! \brief Structure for storing RTP packets for retransmission */
+struct ast_rtp_rtcp_nack_payload {
+ size_t size; /*!< The size of the payload */
+ unsigned char buf[0]; /*!< The payload data */
+};
+
AST_LIST_HEAD_NOLOCK(frame_list, ast_frame);
/* Forward Declarations */
@@ -3675,6 +3686,11 @@ static int ast_rtp_destroy(struct ast_rtp_instance *instance)
rtp->red = NULL;
}
+ /* Destroy the send buffer if it was being used */
+ if (rtp->send_buffer) {
+ ast_data_buffer_free(rtp->send_buffer);
+ }
+
ao2_cleanup(rtp->lasttxformat);
ao2_cleanup(rtp->lastrxformat);
ao2_cleanup(rtp->f.subclass.format);
@@ -4369,7 +4385,7 @@ static int rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame *fr
} else {
/* This is the first frame with sequence number we've seen, so start keeping track */
rtp->expectedseqno = frame->seqno + 1;
- }
+ }
} else {
rtp->expectedseqno = -1;
}
@@ -4383,13 +4399,27 @@ static int rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame *fr
/* If we know the remote address construct a packet and send it out */
if (!ast_sockaddr_isnull(&remote_address)) {
int hdrlen = 12, res, ice;
+ int packet_len = frame->datalen + hdrlen;
unsigned char *rtpheader = (unsigned char *)(frame->data.ptr - hdrlen);
put_unaligned_uint32(rtpheader, htonl((2 << 30) | (codec << 16) | (seqno) | (mark << 23)));
put_unaligned_uint32(rtpheader + 4, htonl(rtp->lastts));
put_unaligned_uint32(rtpheader + 8, htonl(rtp->ssrc));
- if ((res = rtp_sendto(instance, (void *)rtpheader, frame->datalen + hdrlen, 0, &remote_address, &ice)) < 0) {
+ /* If retransmissions are enabled, we need to store this packet for future use */
+ if (rtp->send_buffer) {
+ struct ast_rtp_rtcp_nack_payload *payload;
+
+ payload = ast_malloc(sizeof(*payload) + packet_len);
+ if (payload) {
+ payload->size = packet_len;
+ memcpy(payload->buf, rtpheader, packet_len);
+ ast_data_buffer_put(rtp->send_buffer, rtp->seqno, payload);
+ }
+ }
+
+ res = rtp_sendto(instance, (void *)rtpheader, packet_len, 0, &remote_address, &ice);
+ if (res < 0) {
if (!ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT) || (ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT) && (ast_test_flag(rtp, FLAG_NAT_ACTIVE) == FLAG_NAT_ACTIVE))) {
ast_debug(1, "RTP Transmission error of packet %d to %s: %s\n",
rtp->seqno,
@@ -5145,8 +5175,8 @@ static void update_lost_stats(struct ast_rtp *rtp, unsigned int lost_packets)
}
/*! \pre instance is locked */
-static struct ast_rtp_instance *rtp_find_instance_by_ssrc(struct ast_rtp_instance *instance,
- struct ast_rtp *rtp, unsigned int ssrc)
+static struct ast_rtp_instance *__rtp_find_instance_by_ssrc(struct ast_rtp_instance *instance,
+ struct ast_rtp *rtp, unsigned int ssrc, int source)
{
int index;
@@ -5158,8 +5188,9 @@ static struct ast_rtp_instance *rtp_find_instance_by_ssrc(struct ast_rtp_instanc
/* Find the bundled child instance */
for (index = 0; index < AST_VECTOR_SIZE(&rtp->ssrc_mapping); ++index) {
struct rtp_ssrc_mapping *mapping = AST_VECTOR_GET_ADDR(&rtp->ssrc_mapping, index);
+ unsigned int mapping_ssrc = source ? ast_rtp_get_ssrc(mapping->instance) : mapping->ssrc;
- if (mapping->ssrc_valid && mapping->ssrc == ssrc) {
+ if (mapping->ssrc_valid && mapping_ssrc == ssrc) {
return mapping->instance;
}
}
@@ -5171,6 +5202,20 @@ static struct ast_rtp_instance *rtp_find_instance_by_ssrc(struct ast_rtp_instanc
return NULL;
}
+/*! \pre instance is locked */
+static struct ast_rtp_instance *rtp_find_instance_by_packet_source_ssrc(struct ast_rtp_instance *instance,
+ struct ast_rtp *rtp, unsigned int ssrc)
+{
+ return __rtp_find_instance_by_ssrc(instance, rtp, ssrc, 0);
+}
+
+/*! \pre instance is locked */
+static struct ast_rtp_instance *rtp_find_instance_by_media_source_ssrc(struct ast_rtp_instance *instance,
+ struct ast_rtp *rtp, unsigned int ssrc)
+{
+ return __rtp_find_instance_by_ssrc(instance, rtp, ssrc, 1);
+}
+
static const char *rtcp_payload_type2str(unsigned int pt)
{
const char *str;
@@ -5203,6 +5248,69 @@ static const char *rtcp_payload_type2str(unsigned int pt)
return str;
}
+/*! \pre instance is locked */
+static int ast_rtp_rtcp_handle_nack(struct ast_rtp_instance *instance, unsigned int *nackdata, unsigned int position,
+ unsigned int length)
+{
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+ int res = 0;
+ int blp_index;
+ int packet_index;
+ int ice;
+ struct ast_rtp_rtcp_nack_payload *payload;
+ unsigned int current_word;
+ unsigned int pid; /* Packet ID which refers to seqno of lost packet */
+ unsigned int blp; /* Bitmask of following lost packets */
+ struct ast_sockaddr remote_address = { {0,} };
+
+ if (!rtp->send_buffer) {
+ ast_debug(1, "Tried to handle NACK request, but we don't have a RTP packet storage!\n");
+ return res;
+ }
+
+ ast_rtp_instance_get_remote_address(instance, &remote_address);
+
+ /*
+ * We use index 3 because with feedback messages, the FCI (Feedback Control Information)
+ * does not begin until after the version, packet SSRC, and media SSRC words.
+ */
+ for (packet_index = 3; packet_index < length; packet_index++) {
+ current_word = ntohl(nackdata[position + packet_index]);
+ pid = current_word >> 16;
+ /* We know the remote end is missing this packet. Go ahead and send it if we still have it. */
+ payload = (struct ast_rtp_rtcp_nack_payload *)ast_data_buffer_get(rtp->send_buffer, pid);
+ if (payload) {
+ res += rtp_sendto(instance, payload->buf, payload->size, 0, &remote_address, &ice);
+ } else {
+ ast_debug(1, "Received NACK request for RTP packet with seqno %d, but we don't have it\n", pid);
+ }
+ /*
+ * The bitmask. Denoting the least significant bit as 1 and its most significant bit
+ * as 16, then bit i of the bitmask is set to 1 if the receiver has not received RTP
+ * packet (pid+i)(modulo 2^16). Otherwise, it is set to 0. We cannot assume bits set
+ * to 0 after a bit set to 1 have actually been received.
+ */
+ blp = current_word & 0xFF;
+ blp_index = 1;
+ while (blp) {
+ if (blp & 1) {
+ /* Packet (pid + i)(modulo 2^16) is missing too. */
+ unsigned int seqno = (pid + blp_index) % 65536;
+ payload = (struct ast_rtp_rtcp_nack_payload *)ast_data_buffer_get(rtp->send_buffer, seqno);
+ if (payload) {
+ res += rtp_sendto(instance, payload->buf, payload->size, 0, &remote_address, &ice);
+ } else {
+ ast_debug(1, "Remote end also requested RTP packet with seqno %d, but we don't have it\n", seqno);
+ }
+ }
+ blp >>= 1;
+ blp_index++;
+ }
+ }
+
+ return res;
+}
+
/*
* Unshifted RTCP header bit field masks
*/
@@ -5243,6 +5351,7 @@ static const char *rtcp_payload_type2str(unsigned int pt)
#define RTCP_RR_BLOCK_WORD_LENGTH 6
#define RTCP_HEADER_SSRC_LENGTH 2
#define RTCP_FB_REMB_BLOCK_WORD_LENGTH 4
+#define RTCP_FB_NACK_BLOCK_WORD_LENGTH 2
static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, const unsigned char *rtcpdata, size_t size, struct ast_sockaddr *addr)
{
@@ -5319,6 +5428,8 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c
unsigned int ssrc_valid;
unsigned int length;
unsigned int min_length;
+ /*! Always use packet source SSRC to find the rtp instance unless explicitly told not to. */
+ unsigned int use_packet_source = 1;
struct ast_json *message_blob;
RAII_VAR(struct ast_rtp_rtcp_report *, rtcp_report, NULL, ao2_cleanup);
@@ -5341,9 +5452,20 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c
/* fall through */
case RTCP_PT_RR:
min_length += (rc * RTCP_RR_BLOCK_WORD_LENGTH);
+ use_packet_source = 0;
break;
case RTCP_PT_FUR:
break;
+ case AST_RTP_RTCP_RTPFB:
+ switch (rc) {
+ case AST_RTP_RTCP_FMT_NACK:
+ min_length += RTCP_FB_NACK_BLOCK_WORD_LENGTH;
+ break;
+ default:
+ break;
+ }
+ use_packet_source = 0;
+ break;
case RTCP_PT_PSFB:
switch (rc) {
case AST_RTP_RTCP_FMT_REMB:
@@ -5392,13 +5514,16 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c
}
rtcp_report->reception_report_count = rc;
- ssrc = ntohl(rtcpheader[i + 1]);
+ ssrc = ntohl(rtcpheader[i + 2]);
rtcp_report->ssrc = ssrc;
break;
case RTCP_PT_FUR:
case RTCP_PT_PSFB:
ssrc = ntohl(rtcpheader[i + 1]);
break;
+ case AST_RTP_RTCP_RTPFB:
+ ssrc = ntohl(rtcpheader[i + 2]);
+ break;
case RTCP_PT_SDES:
case RTCP_PT_BYE:
default:
@@ -5417,7 +5542,15 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c
/* Determine the appropriate instance for this */
if (ssrc_valid) {
- child = rtp_find_instance_by_ssrc(transport, transport_rtp, ssrc);
+ /*
+ * Depending on the payload type, either the packet source or media source
+ * SSRC is used.
+ */
+ if (use_packet_source) {
+ child = rtp_find_instance_by_packet_source_ssrc(transport, transport_rtp, ssrc);
+ } else {
+ child = rtp_find_instance_by_media_source_ssrc(transport, transport_rtp, ssrc);
+ }
if (child && child != transport) {
/*
* It is safe to hold the child lock while holding the parent lock.
@@ -5438,7 +5571,7 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c
}
if (ssrc_valid && rtp->themssrc_valid) {
- if (ssrc != rtp->themssrc) {
+ if (ssrc != rtp->themssrc && use_packet_source) {
/*
* Skip over this RTCP record as it does not contain the
* correct SSRC. We should not act upon RTCP records
@@ -5581,6 +5714,24 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c
transport_rtp->f.src = "RTP";
f = &transport_rtp->f;
break;
+ case AST_RTP_RTCP_RTPFB:
+ switch (rc) {
+ case AST_RTP_RTCP_FMT_NACK:
+ /* If retransmissions are not enabled ignore this message */
+ if (!rtp->send_buffer) {
+ break;
+ }
+
+ if (rtcp_debug_test_addr(addr)) {
+ ast_verbose("Received generic RTCP NACK message\n");
+ }
+
+ ast_rtp_rtcp_handle_nack(instance, rtcpheader, position, length);
+ break;
+ default:
+ break;
+ }
+ break;
case RTCP_PT_FUR:
/* Handle RTCP FUR as FIR by setting the format to 4 */
rc = AST_RTP_RTCP_FMT_FIR;
@@ -5981,7 +6132,7 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
ssrc = ntohl(rtpheader[2]);
/* Determine the appropriate instance for this */
- child = rtp_find_instance_by_ssrc(instance, rtp, ssrc);
+ child = rtp_find_instance_by_packet_source_ssrc(instance, rtp, ssrc);
if (!child) {
/* Neither the bundled parent nor any child has this SSRC */
return &ast_null_frame;
@@ -6614,6 +6765,8 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
}
} else if (property == AST_RTP_PROPERTY_ASYMMETRIC_CODEC) {
rtp->asymmetric_codec = value;
+ } else if (property == AST_RTP_PROPERTY_RETRANS_SEND) {
+ rtp->send_buffer = ast_data_buffer_alloc(ast_free_ptr, DEFAULT_RTP_BUFFER_SIZE);
}
}
diff --git a/res/res_sdp_translator_pjmedia.c b/res/res_sdp_translator_pjmedia.c
deleted file mode 100644
index 676e740bc..000000000
--- a/res/res_sdp_translator_pjmedia.c
+++ /dev/null
@@ -1,605 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium, Inc.
- *
- * Mark Michelson <mmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-#include "asterisk.h"
-
-#include <pjlib.h>
-#include <pjmedia.h>
-
-#include "asterisk/res_pjproject.h"
-#include "asterisk/sdp_translator.h"
-#include "asterisk/sdp_options.h"
-#include "asterisk/vector.h"
-#include "asterisk/netsock2.h"
-#include "asterisk/utils.h"
-#include "asterisk/config.h"
-#include "asterisk/test.h"
-#include "asterisk/module.h"
-
-#include "asterisk/sdp.h"
-
-/*** MODULEINFO
- <depend>pjproject</depend>
- <support_level>core</support_level>
- ***/
-
-/*
- * XXX TODO: The memory in the pool is held onto longer than necessary. It
- * is kept and grows for the duration of the associated chan_pjsip session.
- *
- * The translation API does not need to be so generic. The users will know
- * at compile time what the non-Asterisk SDP format they have or need. They
- * should simply call the specific translation functions. However, to make
- * this a loadable module we need to be able to keep it in memory when a
- * dependent module is loaded.
- *
- * To address both issues I propose this API:
- *
- * void ast_sdp_translate_pjmedia_ref(void) - Inc this module's user ref
- * void ast_sdp_translate_pjmedia_unref(void) - Dec this module's user ref.
- * The res_pjsip_session.c:ast_sip_session_alloc() can call the module ref
- * and the session's destructor can call the module unref.
- *
- * struct ast_sdp *ast_sdp_translate_pjmedia_from(const pjmedia_sdp_session *pjmedia_sdp);
- *
- * pjmedia_sdp_session *ast_sdp_translate_pjmedia_to(const struct ast_sdp *sdp, pj_pool_t *pool);
- * Passing in a memory pool allows the memory to be obtained from an
- * rdata memory pool that will be released when the message processing
- * is complete. This prevents memory from accumulating for the duration
- * of a call.
- *
- * int ast_sdp_translate_pjmedia_set_remote_sdp(struct ast_sdp_state *sdp_state, const pjmedia_sdp_session *remote);
- * const pjmedia_sdp_session *ast_sdp_translate_pjmedia_get_local_sdp(struct ast_sdp_state *sdp_state, pj_pool_t *pool);
- * These two functions just do the bookkeeping to translate and set or get
- * the requested SDP.
- *
- *
- * XXX TODO: This code doesn't handle allocation failures very well. i.e.,
- * It assumes they will never happen.
- *
- * XXX TODO: This code uses ast_alloca() inside loops. Doing so if the number
- * of times through the loop is unconstrained will blow the stack.
- * See dupa_pj_str() usage.
- */
-
-static pj_caching_pool sdp_caching_pool;
-
-
-static void *pjmedia_new(void)
-{
- pj_pool_t *pool;
-
- pool = pj_pool_create(&sdp_caching_pool.factory, "pjmedia sdp translator", 1024, 1024, NULL);
-
- return pool;
-}
-
-static void pjmedia_free(void *translator_priv)
-{
- pj_pool_t *pool = translator_priv;
-
- pj_pool_release(pool);
-}
-
-#define dupa_pj_str(pjstr) \
-({ \
- char *dest = ast_alloca(pjstr.slen + 1); \
- memcpy(dest, pjstr.ptr, pjstr.slen); \
- dest[pjstr.slen] = '\0'; \
- dest; \
-})
-
-static struct ast_sdp_m_line *pjmedia_copy_m_line(struct pjmedia_sdp_media *pjmedia_m_line)
-{
- int i;
-
- struct ast_sdp_c_line *c_line = pjmedia_m_line->conn ?
- ast_sdp_c_alloc(dupa_pj_str(pjmedia_m_line->conn->addr_type),
- dupa_pj_str(pjmedia_m_line->conn->addr)) : NULL;
-
- struct ast_sdp_m_line *m_line = ast_sdp_m_alloc(dupa_pj_str(pjmedia_m_line->desc.media),
- pjmedia_m_line->desc.port, pjmedia_m_line->desc.port_count,
- dupa_pj_str(pjmedia_m_line->desc.transport), c_line);
-
- for (i = 0; i < pjmedia_m_line->desc.fmt_count; ++i) {
- ast_sdp_m_add_payload(m_line,
- ast_sdp_payload_alloc(dupa_pj_str(pjmedia_m_line->desc.fmt[i])));
- }
-
- for (i = 0; i < pjmedia_m_line->attr_count; ++i) {
- ast_sdp_m_add_a(m_line, ast_sdp_a_alloc(dupa_pj_str(pjmedia_m_line->attr[i]->name),
- dupa_pj_str(pjmedia_m_line->attr[i]->value)));
- }
-
- return m_line;
-}
-
-static void pjmedia_copy_a_lines(struct ast_sdp *new_sdp, const pjmedia_sdp_session *pjmedia_sdp)
-{
- int i;
-
- for (i = 0; i < pjmedia_sdp->attr_count; ++i) {
- ast_sdp_add_a(new_sdp, ast_sdp_a_alloc(dupa_pj_str(pjmedia_sdp->attr[i]->name),
- dupa_pj_str(pjmedia_sdp->attr[i]->value)));
- }
-}
-
-static void pjmedia_copy_m_lines(struct ast_sdp *new_sdp,
- const struct pjmedia_sdp_session *pjmedia_sdp)
-{
- int i;
-
- for (i = 0; i < pjmedia_sdp->media_count; ++i) {
- ast_sdp_add_m(new_sdp, pjmedia_copy_m_line(pjmedia_sdp->media[i]));
- }
-}
-
-static struct ast_sdp *pjmedia_to_sdp(const void *in, void *translator_priv)
-{
- const struct pjmedia_sdp_session *pjmedia_sdp = in;
-
- struct ast_sdp_o_line *o_line = ast_sdp_o_alloc(dupa_pj_str(pjmedia_sdp->origin.user),
- pjmedia_sdp->origin.id, pjmedia_sdp->origin.version,
- dupa_pj_str(pjmedia_sdp->origin.addr_type), dupa_pj_str(pjmedia_sdp->origin.addr));
-
- struct ast_sdp_c_line *c_line = pjmedia_sdp->conn ?
- ast_sdp_c_alloc(dupa_pj_str(pjmedia_sdp->conn->addr_type),
- dupa_pj_str(pjmedia_sdp->conn->addr)) : NULL;
-
- struct ast_sdp_s_line *s_line = ast_sdp_s_alloc(dupa_pj_str(pjmedia_sdp->name));
-
- struct ast_sdp_t_line *t_line = ast_sdp_t_alloc(pjmedia_sdp->time.start,
- pjmedia_sdp->time.stop);
-
- struct ast_sdp *new_sdp = ast_sdp_alloc(o_line, c_line, s_line, t_line);
-
- pjmedia_copy_a_lines(new_sdp, pjmedia_sdp);
- pjmedia_copy_m_lines(new_sdp, pjmedia_sdp);
-
- return new_sdp;
-}
-
-static void copy_o_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
- struct ast_sdp_o_line *o_line)
-{
- pjmedia_sdp->origin.id = o_line->session_id;
- pjmedia_sdp->origin.version = o_line->session_version;
- pj_strdup2(pool, &pjmedia_sdp->origin.user, o_line->username);
- pj_strdup2(pool, &pjmedia_sdp->origin.addr_type, o_line->address_type);
- pj_strdup2(pool, &pjmedia_sdp->origin.addr, o_line->address);
- pj_strdup2(pool, &pjmedia_sdp->origin.net_type, "IN");
-}
-
-static void copy_s_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
- struct ast_sdp_s_line *s_line)
-{
- pj_strdup2(pool, &pjmedia_sdp->name, s_line->session_name);
-}
-
-static void copy_t_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
- struct ast_sdp_t_line *t_line)
-{
- pjmedia_sdp->time.start = t_line->start_time;
- pjmedia_sdp->time.stop = t_line->stop_time;
-}
-
-static void copy_c_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_conn **conn,
- struct ast_sdp_c_line *c_line)
-{
- pjmedia_sdp_conn *local_conn;
- local_conn = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_conn);
- pj_strdup2(pool, &local_conn->addr_type, c_line->address_type);
- pj_strdup2(pool, &local_conn->addr, c_line->address);
- pj_strdup2(pool, &local_conn->net_type, "IN");
-
- *conn = local_conn;
-}
-
-static void copy_a_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
- const struct ast_sdp *sdp)
-{
- int i;
-
- for (i = 0; i < ast_sdp_get_a_count(sdp); ++i) {
- pjmedia_sdp_attr *attr;
- pj_str_t value;
- struct ast_sdp_a_line *a_line;
-
- a_line = ast_sdp_get_a(sdp, i);
- pj_strdup2(pool, &value, a_line->value);
- attr = pjmedia_sdp_attr_create(pool, a_line->name, &value);
- pjmedia_sdp_session_add_attr(pjmedia_sdp, attr);
- }
-}
-
-static void copy_a_lines_pjmedia_media(pj_pool_t *pool, pjmedia_sdp_media *media,
- struct ast_sdp_m_line *m_line)
-{
- int i;
-
- for (i = 0; i < ast_sdp_m_get_a_count(m_line); ++i) {
- pjmedia_sdp_attr *attr;
- pj_str_t value;
- struct ast_sdp_a_line *a_line;
-
- a_line = ast_sdp_m_get_a(m_line, i);
- pj_strdup2(pool, &value, a_line->value);
- attr = pjmedia_sdp_attr_create(pool, a_line->name, &value);
- pjmedia_sdp_media_add_attr(media, attr);
- }
-}
-
-static void copy_m_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_media *media,
- struct ast_sdp_m_line *m_line)
-{
- int i;
-
- media->desc.port = m_line->port;
- media->desc.port_count = m_line->port_count;
- pj_strdup2(pool, &media->desc.transport, m_line->proto);
- pj_strdup2(pool, &media->desc.media, m_line->type);
-
- for (i = 0; i < ast_sdp_m_get_payload_count(m_line); ++i) {
- pj_strdup2(pool, &media->desc.fmt[i], ast_sdp_m_get_payload(m_line, i)->fmt);
- ++media->desc.fmt_count;
- }
- if (m_line->c_line && m_line->c_line->address) {
- copy_c_line_pjmedia(pool, &media->conn, m_line->c_line);
- }
- copy_a_lines_pjmedia_media(pool, media, m_line);
-}
-
-static void copy_m_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
- const struct ast_sdp *sdp)
-{
- int i;
-
- for (i = 0; i < ast_sdp_get_m_count(sdp); ++i) {
- pjmedia_sdp_media *media;
-
- media = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_media);
- copy_m_line_pjmedia(pool, media, ast_sdp_get_m(sdp, i));
- pjmedia_sdp->media[pjmedia_sdp->media_count] = media;
- ++pjmedia_sdp->media_count;
- }
-}
-
-static const void *sdp_to_pjmedia(const struct ast_sdp *sdp, void *translator_priv)
-{
- pj_pool_t *pool = translator_priv;
- pjmedia_sdp_session *pjmedia_sdp;
-
- pjmedia_sdp = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_session);
- copy_o_line_pjmedia(pool, pjmedia_sdp, sdp->o_line);
- copy_s_line_pjmedia(pool, pjmedia_sdp, sdp->s_line);
- copy_t_line_pjmedia(pool, pjmedia_sdp, sdp->t_line);
- copy_c_line_pjmedia(pool, &pjmedia_sdp->conn, sdp->c_line);
- copy_a_lines_pjmedia(pool, pjmedia_sdp, sdp);
- copy_m_lines_pjmedia(pool, pjmedia_sdp, sdp);
- return pjmedia_sdp;
-}
-
-static struct ast_sdp_translator_ops pjmedia_translator = {
- .repr = AST_SDP_IMPL_PJMEDIA,
- .translator_new = pjmedia_new,
- .translator_free = pjmedia_free,
- .to_sdp = pjmedia_to_sdp,
- .from_sdp = sdp_to_pjmedia,
-};
-
-#ifdef TEST_FRAMEWORK
-
-static int verify_s_line(struct ast_sdp_s_line *s_line, char *expected)
-{
- return strcmp(s_line->session_name, expected) == 0;
-}
-
-static int verify_c_line(struct ast_sdp_c_line *c_line, char *family, char *addr)
-{
- return strcmp(c_line->address_type, family) == 0 && strcmp(c_line->address, addr) == 0;
-}
-
-static int verify_t_line(struct ast_sdp_t_line *t_line, uint32_t start, uint32_t end)
-{
- return t_line->start_time == start && t_line->stop_time == end;
-}
-
-static int verify_m_line(struct ast_sdp *sdp, int index, char *type, int port,
- int port_count, char *profile, ...)
-{
- struct ast_sdp_m_line *m_line;
- int res;
- va_list ap;
- int i;
-
- m_line = ast_sdp_get_m(sdp, index);
-
- res = strcmp(m_line->type, type) == 0;
- res |= m_line->port == port;
- res |= m_line->port_count == port_count;
- res |= strcmp(m_line->proto, profile) == 0;
-
- va_start(ap, profile);
- for (i = 0; i < ast_sdp_m_get_payload_count(m_line); ++i) {
- char *payload;
-
- payload = va_arg(ap, char *);
- if (!payload) {
- res = -1;
- break;
- }
- res |= strcmp(ast_sdp_m_get_payload(m_line, i)->fmt, payload) == 0;
- }
- va_end(ap);
- return res;
-}
-
-static int verify_a_line(struct ast_sdp *sdp, int m_index, int a_index, char *name,
- char *value)
-{
- struct ast_sdp_m_line *m_line;
- struct ast_sdp_a_line *a_line;
-
- m_line = ast_sdp_get_m(sdp, m_index);
- a_line = ast_sdp_m_get_a(m_line, a_index);
-
- return strcmp(a_line->name, name) == 0 && strcmp(a_line->value, value) == 0;
-}
-
-AST_TEST_DEFINE(pjmedia_to_sdp_test)
-{
- struct ast_sdp_translator *translator;
- pj_pool_t *pool;
- char *sdp_str =
- "v=0\r\n"
- "o=alice 2890844526 2890844527 IN IP4 host.atlanta.example.com\r\n"
- "s= \r\n"
- "c=IN IP4 host.atlanta.example.com\r\n"
- "t=123 456\r\n"
- "m=audio 49170 RTP/AVP 0 8 97\r\n"
- "a=rtpmap:0 PCMU/8000\r\n"
- "a=rtpmap:8 PCMA/8000\r\n"
- "a=rtpmap:97 iLBC/8000\r\n"
- "a=sendrecv\r\n"
- "m=video 51372 RTP/AVP 31 32\r\n"
- "a=rtpmap:31 H261/90000\r\n"
- "a=rtpmap:32 MPV/90000\r\n";
- pjmedia_sdp_session *pjmedia_sdp;
- struct ast_sdp *sdp = NULL;
- pj_status_t status;
- enum ast_test_result_state res = AST_TEST_PASS;
-
- switch (cmd) {
- case TEST_INIT:
- info->name = "pjmedia_to_sdp";
- info->category = "/main/sdp/";
- info->summary = "PJMEDIA to SDP unit test";
- info->description =
- "Ensures PJMEDIA SDPs are translated correctly";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- pool = pj_pool_create(&sdp_caching_pool.factory, "pjmedia to sdp test", 1024, 1024, NULL);
-
- translator = ast_sdp_translator_new(AST_SDP_IMPL_PJMEDIA);
- if (!translator) {
- ast_test_status_update(test, "Failed to create SDP translator\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- }
-
- status = pjmedia_sdp_parse(pool, sdp_str, strlen(sdp_str), &pjmedia_sdp);
- if (status != PJ_SUCCESS) {
- ast_test_status_update(test, "Error parsing SDP\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- }
-
- sdp = ast_sdp_translator_to_sdp(translator, pjmedia_sdp);
-
- if (strcmp(sdp->o_line->username, "alice")) {
- ast_test_status_update(test, "Unexpected SDP user '%s'\n", sdp->o_line->username);
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (sdp->o_line->session_id != 2890844526UL) {
- ast_test_status_update(test, "Unexpected SDP id '%" PRId64 "lu'\n", sdp->o_line->session_id);
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (sdp->o_line->session_version != 2890844527UL) {
- ast_test_status_update(test, "Unexpected SDP version '%" PRId64 "'\n", sdp->o_line->session_version);
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (strcmp(sdp->o_line->address_type, "IP4")) {
- ast_test_status_update(test, "Unexpected address family '%s'\n", sdp->o_line->address_type);
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (strcmp(sdp->o_line->address, "host.atlanta.example.com")) {
- ast_test_status_update(test, "Unexpected address '%s'\n", sdp->o_line->address);
- res = AST_TEST_FAIL;
- goto cleanup;
- }
-
- if (!verify_s_line(sdp->s_line, " ")) {
- ast_test_status_update(test, "Bad s line\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (!verify_c_line(sdp->c_line, "IP4", "host.atlanta.example.com")) {
- ast_test_status_update(test, "Bad c line\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (!verify_t_line(sdp->t_line, 123, 456)) {
- ast_test_status_update(test, "Bad t line\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- }
-
- if (!verify_m_line(sdp, 0, "audio", 49170, 1, "RTP/AVP", "0", "8", "97", NULL)) {
- ast_test_status_update(test, "Bad m line 1\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (!verify_a_line(sdp, 0, 0, "rtpmap", "0 PCMU/8000")) {
- ast_test_status_update(test, "Bad a line 1\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (!verify_a_line(sdp, 0, 1, "rtpmap", "8 PCMA/8000")) {
- ast_test_status_update(test, "Bad a line 2\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (!verify_a_line(sdp, 0, 2, "rtpmap", "97 iLBC/8000")) {
- ast_test_status_update(test, "Bad a line 3\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (!verify_a_line(sdp, 0, 3, "sendrecv", "")) {
- ast_test_status_update(test, "Bad a line 3\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (!verify_m_line(sdp, 1, "video", 51372, 1, "RTP/AVP", "31", "32", NULL)) {
- ast_test_status_update(test, "Bad m line 2\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (!verify_a_line(sdp, 1, 0, "rtpmap", "31 H261/90000")) {
- ast_test_status_update(test, "Bad a line 4\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- } else if (!verify_a_line(sdp, 1, 1, "rtpmap", "32 MPV/90000")) {
- ast_test_status_update(test, "Bad a line 5\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- }
-
-cleanup:
- ao2_cleanup(sdp);
- ast_sdp_translator_free(translator);
- pj_pool_release(pool);
- return res;
-}
-
-AST_TEST_DEFINE(sdp_to_pjmedia_test)
-{
- struct ast_sdp_translator *translator;
- char *sdp_str =
- "v=0\r\n"
- "o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com\r\n"
- "s= \r\n"
- "c=IN IP4 host.atlanta.example.com\r\n"
- "t=123 456\r\n"
- "m=audio 49170 RTP/AVP 0 8 97\r\n"
- "a=rtpmap:0 PCMU/8000\r\n"
- "a=rtpmap:8 PCMA/8000\r\n"
- "a=rtpmap:97 iLBC/8000\r\n"
- "a=sendrecv\r\n"
- "m=video 51372 RTP/AVP 31 32\r\n"
- "a=rtpmap:31 H261/90000\r\n"
- "a=rtpmap:32 MPV/90000\r\n\r\n";
- pj_pool_t *pool;
- pjmedia_sdp_session *pjmedia_sdp_orig;
- const pjmedia_sdp_session *pjmedia_sdp_dup;
- struct ast_sdp *sdp = NULL;
- pj_status_t status;
- enum ast_test_result_state res = AST_TEST_PASS;
- char buf[2048];
- char errbuf[256];
-
- switch (cmd) {
- case TEST_INIT:
- info->name = "sdp_to_pjmedia";
- info->category = "/main/sdp/";
- info->summary = "SDP to PJMEDIA unit test";
- info->description =
- "Ensures PJMEDIA SDPs are translated correctly";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- pool = pj_pool_create(&sdp_caching_pool.factory, "pjmedia to sdp test", 1024, 1024, NULL);
-
- translator = ast_sdp_translator_new(AST_SDP_IMPL_PJMEDIA);
- if (!translator) {
- ast_test_status_update(test, "Failed to create SDP translator\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- }
-
- status = pjmedia_sdp_parse(pool, sdp_str, strlen(sdp_str), &pjmedia_sdp_orig);
- if (status != PJ_SUCCESS) {
- ast_test_status_update(test, "Error parsing SDP\n");
- res = AST_TEST_FAIL;
- goto cleanup;
- }
-
- sdp = ast_sdp_translator_to_sdp(translator, pjmedia_sdp_orig);
- pjmedia_sdp_dup = ast_sdp_translator_from_sdp(translator, sdp);
-
- if ((status = pjmedia_sdp_session_cmp(pjmedia_sdp_orig, pjmedia_sdp_dup, 0)) != PJ_SUCCESS) {
- ast_test_status_update(test, "SDPs aren't equal\n");
- pjmedia_sdp_print(pjmedia_sdp_orig, buf, sizeof(buf));
- ast_test_status_update(test, "Original SDP is %s\n", buf);
- pjmedia_sdp_print(pjmedia_sdp_dup, buf, sizeof(buf));
- ast_test_status_update(test, "New SDP is %s\n", buf);
- pjmedia_strerror(status, errbuf, sizeof(errbuf));
- ast_test_status_update(test, "PJMEDIA says %d: '%s'\n", status, errbuf);
- res = AST_TEST_FAIL;
- goto cleanup;
- }
-
-cleanup:
- ao2_cleanup(sdp);
- ast_sdp_translator_free(translator);
- pj_pool_release(pool);
- return res;
-}
-
-#endif /* TEST_FRAMEWORK */
-
-static int load_module(void)
-{
- if (ast_sdp_register_translator(&pjmedia_translator)) {
- return AST_MODULE_LOAD_DECLINE;
- }
- ast_pjproject_caching_pool_init(&sdp_caching_pool, NULL, 1024 * 1024);
- AST_TEST_REGISTER(pjmedia_to_sdp_test);
- AST_TEST_REGISTER(sdp_to_pjmedia_test);
-
- return AST_MODULE_LOAD_SUCCESS;
-}
-
-static int unload_module(void)
-{
- ast_sdp_unregister_translator(&pjmedia_translator);
- ast_pjproject_caching_pool_destroy(&sdp_caching_pool);
- AST_TEST_UNREGISTER(pjmedia_to_sdp_test);
- AST_TEST_UNREGISTER(sdp_to_pjmedia_test);
- return 0;
-}
-
-static int reload_module(void)
-{
- return 0;
-}
-
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJMEDIA SDP Translator",
- .support_level = AST_MODULE_SUPPORT_CORE,
- .load = load_module,
- .unload = unload_module,
- .reload = reload_module,
- .load_pri = AST_MODPRI_CHANNEL_DEPEND,
- .requires = "res_pjproject",
-);
diff --git a/rest-api-templates/api.wiki.mustache b/rest-api-templates/api.wiki.mustache
index ad12bb695..a51c3e6ce 100644
--- a/rest-api-templates/api.wiki.mustache
+++ b/rest-api-templates/api.wiki.mustache
@@ -5,7 +5,7 @@ h1. {{name_title}}
{{#apis}}
{{#operations}}
-| {{http_method}} | [{{wiki_path}}|#{{nickname}}] | {{#response_class}}{{#is_primitive}}{{name}}{{/is_primitive}}{{^is_primitive}}[{{wiki_name}}|{{wiki_prefix}} REST Data Models#{{singular_name}}]{{/is_primitive}}{{/response_class}} | {{summary}} |
+| {{http_method}} | [{{wiki_path}}|#{{nickname}}] | {{#response_class}}{{#is_primitive}}{{name}}{{/is_primitive}}{{^is_primitive}}[{{wiki_name}}|{{wiki_prefix}} REST Data Models#{{singular_name}}]{{/is_primitive}}{{/response_class}} | {{{summary}}} |
{{/operations}}
{{/apis}}
{{#apis}}
diff --git a/rest-api-templates/ari_resource.h.mustache b/rest-api-templates/ari_resource.h.mustache
index df075af35..c1d880d30 100644
--- a/rest-api-templates/ari_resource.h.mustache
+++ b/rest-api-templates/ari_resource.h.mustache
@@ -76,7 +76,7 @@ int ast_ari_{{c_name}}_{{c_nickname}}_parse_body(
{{/parse_body}}
/*!
- * \brief {{summary}}
+ * \brief {{{summary}}}
{{#notes}}
*
* {{{notes}}}
@@ -99,7 +99,7 @@ void ast_ari_{{c_name}}_{{c_nickname}}(struct ast_tcptls_session_instance *ser,
{{#is_websocket}}
/*!
- * \brief {{summary}}
+ * \brief {{{summary}}}
{{#notes}}
*
* {{{notes}}}
@@ -111,7 +111,7 @@ void ast_ari_{{c_name}}_{{c_nickname}}(struct ast_tcptls_session_instance *ser,
int ast_ari_websocket_{{c_name}}_{{c_nickname}}_init(void);
/*!
- * \brief {{summary}}
+ * \brief {{{summary}}}
{{#notes}}
*
* {{{notes}}}
diff --git a/rest-api-templates/asterisk_processor.py b/rest-api-templates/asterisk_processor.py
index 981294673..5f8dbb576 100644
--- a/rest-api-templates/asterisk_processor.py
+++ b/rest-api-templates/asterisk_processor.py
@@ -23,7 +23,7 @@ Asterisk RESTful HTTP binding code.
import os
import re
-from swagger_model import *
+from swagger_model import Stringify, SwaggerError, SwaggerPostProcessor
try:
from collections import OrderedDict
@@ -183,7 +183,7 @@ class AsteriskProcessor(SwaggerPostProcessor):
raise SwaggerError(
"Should not mix resources in one API declaration", context)
# root_path isn't needed any more
- resource_api.root_path = resource_api.root_path.children()[0]
+ resource_api.root_path = list(resource_api.root_path.children())[0]
if resource_api.name != resource_api.root_path.name:
raise SwaggerError(
"API declaration name should match", context)
@@ -206,10 +206,10 @@ class AsteriskProcessor(SwaggerPostProcessor):
def process_parameter(self, parameter, context):
if parameter.param_type == 'body':
- parameter.is_body_parameter = True;
+ parameter.is_body_parameter = True;
parameter.c_data_type = 'struct ast_json *'
else:
- parameter.is_body_parameter = False;
+ parameter.is_body_parameter = False;
if not parameter.data_type in self.type_mapping:
raise SwaggerError(
"Invalid parameter type %s" % parameter.data_type, context)
diff --git a/rest-api-templates/make_ari_stubs.py b/rest-api-templates/make_ari_stubs.py
index 0aba06d6d..a25773df4 100755
--- a/rest-api-templates/make_ari_stubs.py
+++ b/rest-api-templates/make_ari_stubs.py
@@ -16,19 +16,20 @@
# at the top of the source tree.
#
+from __future__ import print_function
import sys
try:
import pystache
except ImportError:
- print >> sys.stderr, "Pystache required. Please sudo pip install pystache."
+ print("Pystache required. Please sudo pip install pystache.", file=sys.stderr)
sys.exit(1)
import os.path
from asterisk_processor import AsteriskProcessor
from optparse import OptionParser
-from swagger_model import *
+from swagger_model import ResourceListing
from transform import Transform
TOPDIR = os.path.dirname(os.path.abspath(__file__))
diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache
index 67a04d898..85948fba1 100644
--- a/rest-api-templates/res_ari_resource.c.mustache
+++ b/rest-api-templates/res_ari_resource.c.mustache
@@ -55,7 +55,7 @@
#if defined(AST_DEVMODE)
#include "ari/ari_model_validators.h"
#endif
-{{^has_websocket}}
+{{#has_websocket}}
{{! Only include http_websocket if necessary. Otherwise we'll do a lot of
* unnecessary optional_api intialization, which makes optional_api harder
* to debug
@@ -278,7 +278,7 @@ static int load_module(void)
{{#apis}}
{{#operations}}
-{{#has_websocket}}
+{{#is_websocket}}
struct ast_websocket_protocol *protocol;
if (ast_ari_websocket_{{c_name}}_{{c_nickname}}_init() == -1) {
@@ -300,8 +300,6 @@ static int load_module(void)
}
protocol->session_attempted = ast_ari_{{c_name}}_{{c_nickname}}_ws_attempted_cb;
protocol->session_established = ast_ari_{{c_name}}_{{c_nickname}}_ws_established_cb;
-{{/has_websocket}}
-{{#is_websocket}}
res |= ast_websocket_server_add_protocol2({{full_name}}.ws_server, protocol);
{{/is_websocket}}
{{/operations}}
diff --git a/rest-api-templates/swagger_model.py b/rest-api-templates/swagger_model.py
index 3f729d8b5..50c5fb07b 100644
--- a/rest-api-templates/swagger_model.py
+++ b/rest-api-templates/swagger_model.py
@@ -26,6 +26,7 @@ missing, or have incorrect values).
See https://github.com/wordnik/swagger-core/wiki/API-Declaration for the spec.
"""
+from __future__ import print_function
import json
import os.path
import pprint
@@ -75,7 +76,7 @@ def compare_versions(lhs, rhs):
'''
lhs = [int(v) for v in lhs.split('.')]
rhs = [int(v) for v in rhs.split('.')]
- return cmp(lhs, rhs)
+ return (lhs > rhs) - (lhs < rhs)
class ParsingContext(object):
@@ -444,8 +445,7 @@ class Api(Stringify):
op_json = api_json.get('operations')
self.operations = [
Operation().load(j, processor, context) for j in op_json]
- self.has_websocket = \
- filter(lambda op: op.is_websocket, self.operations) != []
+ self.has_websocket = any(op.is_websocket for op in self.operations)
processor.process_api(self, context)
return self
@@ -611,7 +611,7 @@ class ApiDeclaration(Stringify):
except SwaggerError:
raise
except Exception as e:
- print >> sys.stderr, "Error: ", traceback.format_exc()
+ print("Error: ", traceback.format_exc(), file=sys.stderr)
raise SwaggerError(
"Error loading %s" % api_declaration_file, context, e)
@@ -624,8 +624,8 @@ class ApiDeclaration(Stringify):
.replace(".json", ".{format}")
if self.resource_path != expected_resource_path:
- print >> sys.stderr, \
- "%s != %s" % (self.resource_path, expected_resource_path)
+ print("%s != %s" % (self.resource_path, expected_resource_path),
+ file=sys.stderr)
raise SwaggerError("resourcePath has incorrect value", context)
return self
@@ -656,8 +656,7 @@ class ApiDeclaration(Stringify):
if api.path in paths:
raise SwaggerError("API with duplicated path: %s" % api.path, context)
paths.add(api.path)
- self.has_websocket = filter(lambda api: api.has_websocket,
- self.apis) == []
+ self.has_websocket = any(api.has_websocket for api in self.apis)
models = api_decl_json.get('models').items() or []
self.models = [Model().load(id, json, processor, context)
for (id, json) in models]
@@ -666,7 +665,7 @@ class ApiDeclaration(Stringify):
model_dict = dict((m.id, m) for m in self.models)
for m in self.models:
def link_subtype(name):
- res = model_dict.get(subtype)
+ res = model_dict.get(name)
if not res:
raise SwaggerError("%s has non-existing subtype %s",
m.id, name)
@@ -725,7 +724,7 @@ class ResourceListing(Stringify):
except SwaggerError:
raise
except Exception as e:
- print >> sys.stderr, "Error: ", traceback.format_exc()
+ print("Error: ", traceback.format_exc(), file=sys.stderr)
raise SwaggerError(
"Error loading %s" % resource_file, context, e)
diff --git a/rest-api-templates/transform.py b/rest-api-templates/transform.py
index c3a030064..88f7d2e67 100644
--- a/rest-api-templates/transform.py
+++ b/rest-api-templates/transform.py
@@ -21,6 +21,11 @@ import os.path
import pystache
import shutil
import tempfile
+import sys
+
+if sys.version_info[0] == 3:
+ def unicode(v):
+ return str(v)
class Transform(object):
@@ -52,10 +57,10 @@ class Transform(object):
dest_exists = os.path.exists(dest_file)
if dest_exists and not self.overwrite:
return
- with tempfile.NamedTemporaryFile() as out:
+ with tempfile.NamedTemporaryFile(mode='w+') as out:
out.write(renderer.render(self.template, model))
out.flush()
if not dest_exists or not filecmp.cmp(out.name, dest_file):
- print "Writing %s" % dest_file
+ print("Writing %s" % dest_file)
shutil.copyfile(out.name, dest_file)
diff --git a/tests/test_sdp.c b/tests/test_sdp.c
deleted file mode 100644
index 0ab8ec8ae..000000000
--- a/tests/test_sdp.c
+++ /dev/null
@@ -1,2105 +0,0 @@
-/*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2017, Digium Inc.
- *
- * Mark Michelson <mmmichelson@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
-
-/*** MODULEINFO
- <depend>TEST_FRAMEWORK</depend>
- <support_level>core</support_level>
- ***/
-
-#include "asterisk.h"
-#include "asterisk/test.h"
-#include "asterisk/module.h"
-#include "asterisk/sdp.h"
-#include "asterisk/stream.h"
-#include "asterisk/format.h"
-#include "asterisk/format_cache.h"
-#include "asterisk/format_cap.h"
-#include "asterisk/rtp_engine.h"
-
-static int validate_o_line(struct ast_test *test, const struct ast_sdp_o_line *o_line,
- const char *sdpowner, const char *address_type, const char *address)
-{
- if (!o_line) {
- return -1;
- }
-
- if (strcmp(o_line->username, sdpowner)) {
- ast_test_status_update(test, "Expected o-line SDP owner %s but got %s\n",
- sdpowner, o_line->username);
- return -1;
- }
-
- if (strcmp(o_line->address_type, address_type)) {
- ast_test_status_update(test, "Expected o-line SDP address type %s but got %s\n",
- address_type, o_line->address_type);
- return -1;
- }
-
- if (strcmp(o_line->address, address)) {
- ast_test_status_update(test, "Expected o-line SDP address %s but got %s\n",
- address, o_line->address);
- return -1;
- }
-
- ast_test_status_update(test, "SDP o-line is as expected!\n");
- return 0;
-}
-
-static int validate_c_line(struct ast_test *test, const struct ast_sdp_c_line *c_line,
- const char *address_type, const char *address)
-{
- if (strcmp(c_line->address_type, address_type)) {
- ast_test_status_update(test, "Expected c-line SDP address type %s but got %s\n",
- address_type, c_line->address_type);
- return -1;
- }
-
- if (strcmp(c_line->address, address)) {
- ast_test_status_update(test, "Expected c-line SDP address %s but got %s\n",
- address, c_line->address);
- return -1;
- }
-
- ast_test_status_update(test, "SDP c-line is as expected!\n");
- return 0;
-}
-
-static int validate_m_line(struct ast_test *test, const struct ast_sdp_m_line *m_line,
- const char *media_type, int num_payloads)
-{
- if (strcmp(m_line->type, media_type)) {
- ast_test_status_update(test, "Expected m-line media type %s but got %s\n",
- media_type, m_line->type);
- return -1;
- }
-
- if (m_line->port == 0) {
- ast_test_status_update(test, "Expected %s m-line to not be declined\n",
- media_type);
- return -1;
- }
-
- if (ast_sdp_m_get_payload_count(m_line) != num_payloads) {
- ast_test_status_update(test, "Expected %s m-line payload count %d but got %d\n",
- media_type, num_payloads, ast_sdp_m_get_payload_count(m_line));
- return -1;
- }
-
- ast_test_status_update(test, "SDP %s m-line is as expected\n", media_type);
- return 0;
-}
-
-static int validate_m_line_declined(struct ast_test *test,
- const struct ast_sdp_m_line *m_line, const char *media_type)
-{
- if (strcmp(m_line->type, media_type)) {
- ast_test_status_update(test, "Expected m-line media type %s but got %s\n",
- media_type, m_line->type);
- return -1;
- }
-
- if (m_line->port != 0) {
- ast_test_status_update(test, "Expected %s m-line to be declined but got port %u\n",
- media_type, m_line->port);
- return -1;
- }
-
- ast_test_status_update(test, "SDP %s m-line is as expected\n", media_type);
- return 0;
-}
-
-static int validate_rtpmap(struct ast_test *test, const struct ast_sdp_m_line *m_line,
- const char *media_name)
-{
- struct ast_sdp_a_line *a_line;
- int i;
-
- for (i = 0; i < ast_sdp_m_get_a_count(m_line); ++i) {
- struct ast_sdp_rtpmap *rtpmap;
- int match;
-
- a_line = ast_sdp_m_get_a(m_line, i);
- if (strcmp(a_line->name, "rtpmap")) {
- continue;
- }
-
- rtpmap = ast_sdp_a_get_rtpmap(a_line);
- if (!rtpmap) {
- return -1;
- }
-
- match = !strcmp(rtpmap->encoding_name, media_name);
-
- ast_sdp_rtpmap_free(rtpmap);
- if (match) {
- return 0;
- }
- }
-
- ast_test_status_update(test, "Could not find rtpmap with encoding name %s\n", media_name);
-
- return -1;
-}
-
-static enum ast_test_result_state validate_t38(struct ast_test *test, const struct ast_sdp_m_line *m_line)
-{
- struct ast_sdp_a_line *a_line;
-
- a_line = ast_sdp_m_find_attribute(m_line, "T38FaxVersion", -1);
- ast_test_validate(test, a_line && !strcmp(a_line->value, "0"));
-
- a_line = ast_sdp_m_find_attribute(m_line, "T38FaxMaxBitRate", -1);
- ast_test_validate(test, a_line && !strcmp(a_line->value, "14400"));
-
- a_line = ast_sdp_m_find_attribute(m_line, "T38FaxRateManagement", -1);
- ast_test_validate(test, a_line && !strcmp(a_line->value, "transferredTCF"));
-
- return AST_TEST_PASS;
-}
-
-AST_TEST_DEFINE(invalid_rtpmap)
-{
- /* a=rtpmap: is already assumed. This is the part after that */
- static const char *invalids[] = {
- "J PCMU/8000",
- "0 PCMU:8000",
- "0 PCMU/EIGHT-THOUSAND",
- "0 PCMU/8000million/2",
- "0 PCMU//2",
- "0 /8000/2",
- "0 PCMU/8000/",
- "0 PCMU/8000million",
- };
- int i;
- enum ast_test_result_state res = AST_TEST_PASS;
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "invalid_rtpmap";
- info->category = "/main/sdp/";
- info->summary = "Ensure invalid rtpmaps are rejected";
- info->description =
- "Try to convert several invalid rtpmap attributes. If\n"
- "any succeeds, the test fails.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- for (i = 0; i < ARRAY_LEN(invalids); ++i) {
- struct ast_sdp_a_line *a_line;
- struct ast_sdp_rtpmap *rtpmap;
-
- a_line = ast_sdp_a_alloc("rtpmap", invalids[i]);
- rtpmap = ast_sdp_a_get_rtpmap(a_line);
- if (rtpmap) {
- ast_test_status_update(test, "Invalid rtpmap '%s' was accepted as valid\n",
- invalids[i]);
- res = AST_TEST_FAIL;
- }
- ast_sdp_a_free(a_line);
- ast_sdp_rtpmap_free(rtpmap);
- }
-
- return res;
-}
-
-AST_TEST_DEFINE(rtpmap)
-{
- static const char *valids[] = {
- "0 PCMU/8000",
- "107 opus/48000/2",
- };
- static int payloads[] = {
- 0,
- 107,
- };
- static const char *encoding_names[] = {
- "PCMU",
- "opus",
- };
- static int clock_rates[] = {
- 8000,
- 48000,
- };
- static const char *encoding_parameters[] = {
- "",
- "2",
- };
- int i;
- enum ast_test_result_state res = AST_TEST_PASS;
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "rtpmap";
- info->category = "/main/sdp/";
- info->summary = "Ensure rtpmap attribute values are parsed correctly";
- info->description =
- "Parse several valid rtpmap attributes. Ensure that the parsed values\n"
- "are what we expect";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- for (i = 0; i < ARRAY_LEN(valids); ++i) {
- struct ast_sdp_a_line *a_line;
- struct ast_sdp_rtpmap *rtpmap;
-
- a_line = ast_sdp_a_alloc("rtpmap", valids[i]);
- rtpmap = ast_sdp_a_get_rtpmap(a_line);
- if (!rtpmap) {
- ast_test_status_update(test, "Valid rtpmap '%s' was rejected as invalid\n",
- valids[i]);
- res = AST_TEST_FAIL;
- continue;
- }
- if (rtpmap->payload != payloads[i]) {
- ast_test_status_update(test, "RTPmap payload '%d' does not match expected '%d'\n",
- rtpmap->payload, payloads[i]);
- res = AST_TEST_FAIL;
- }
- if (strcmp(rtpmap->encoding_name, encoding_names[i])) {
- ast_test_status_update(test, "RTPmap encoding_name '%s' does not match expected '%s'\n",
- rtpmap->encoding_name, encoding_names[i]);
- res = AST_TEST_FAIL;
- }
- if (rtpmap->clock_rate != clock_rates[i]) {
- ast_test_status_update(test, "RTPmap clock rate '%d' does not match expected '%d'\n",
- rtpmap->clock_rate, clock_rates[i]);
- res = AST_TEST_FAIL;
- }
- if (strcmp(rtpmap->encoding_parameters, encoding_parameters[i])) {
- ast_test_status_update(test, "RTPmap encoding_parameter '%s' does not match expected '%s'\n",
- rtpmap->encoding_parameters, encoding_parameters[i]);
- res = AST_TEST_FAIL;
- }
- ast_sdp_a_free(a_line);
- ast_sdp_rtpmap_free(rtpmap);
- }
-
- return res;
-}
-
-AST_TEST_DEFINE(find_attr)
-{
- enum ast_test_result_state res = AST_TEST_PASS;
- struct ast_sdp_m_line *m_line;
- struct ast_sdp_a_line *a_line;
- int idx;
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "find_attr";
- info->category = "/main/sdp/";
- info->summary = "Ensure that finding attributes works as expected";
- info->description =
- "A SDP m-line is created, and attributes are added.\n"
- "We then attempt a series of attribute-finding calls that are expected to work\n"
- "followed by a series of attribute-finding calls that are expected fo fail.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- m_line = ast_sdp_m_alloc("audio", 666, 1, "RTP/AVP", NULL);
- if (!m_line) {
- res = AST_TEST_FAIL;
- goto end;
- }
- a_line = ast_sdp_a_alloc("foo", "0 bar");
- if (!a_line) {
- res = AST_TEST_FAIL;
- goto end;
- }
- ast_sdp_m_add_a(m_line, a_line);
- a_line = ast_sdp_a_alloc("foo", "0 bee");
- if (!a_line) {
- res = AST_TEST_FAIL;
- goto end;
- }
- ast_sdp_m_add_a(m_line, a_line);
-
- a_line = ast_sdp_a_alloc("baz", "howdy");
- if (!a_line) {
- res = AST_TEST_FAIL;
- goto end;
- }
- ast_sdp_m_add_a(m_line, a_line);
-
- /* These should work */
- a_line = ast_sdp_m_find_attribute(m_line, "foo", 0);
- if (!a_line || strcmp(a_line->value, "0 bar")) {
- ast_test_status_update(test, "Failed to find attribute 'foo' with payload '0'\n");
- res = AST_TEST_FAIL;
- }
- a_line = ast_sdp_m_find_attribute(m_line, "foo", -1);
- if (!a_line || strcmp(a_line->value, "0 bar")) {
- ast_test_status_update(test, "Failed to find attribute 'foo' with unspecified payload\n");
- res = AST_TEST_FAIL;
- }
- a_line = ast_sdp_m_find_attribute(m_line, "baz", -1);
- if (!a_line || strcmp(a_line->value, "howdy")) {
- ast_test_status_update(test, "Failed to find attribute 'baz' with unspecified payload\n");
- res = AST_TEST_FAIL;
- }
-
- idx = ast_sdp_m_find_a_first(m_line, "foo", 0);
- if (idx < 0) {
- ast_test_status_update(test, "Failed to find first attribute 'foo' with payload '0'\n");
- res = AST_TEST_FAIL;
- goto end;
- }
- a_line = ast_sdp_m_get_a(m_line, idx);
- if (!a_line || strcmp(a_line->value, "0 bar")) {
- ast_test_status_update(test, "Find first attribute 'foo' with payload '0' didn't match\n");
- res = AST_TEST_FAIL;
- }
- idx = ast_sdp_m_find_a_next(m_line, idx, "foo", 0);
- if (idx < 0) {
- ast_test_status_update(test, "Failed to find next attribute 'foo' with payload '0'\n");
- res = AST_TEST_FAIL;
- goto end;
- }
- a_line = ast_sdp_m_get_a(m_line, idx);
- if (!a_line || strcmp(a_line->value, "0 bee")) {
- ast_test_status_update(test, "Find next attribute 'foo' with payload '0' didn't match\n");
- res = AST_TEST_FAIL;
- }
- idx = ast_sdp_m_find_a_next(m_line, idx, "foo", 0);
- if (0 <= idx) {
- ast_test_status_update(test, "Find next attribute 'foo' with payload '0' found too many\n");
- res = AST_TEST_FAIL;
- }
-
- idx = ast_sdp_m_find_a_first(m_line, "foo", -1);
- if (idx < 0) {
- ast_test_status_update(test, "Failed to find first attribute 'foo' with unspecified payload\n");
- res = AST_TEST_FAIL;
- goto end;
- }
- a_line = ast_sdp_m_get_a(m_line, idx);
- if (!a_line || strcmp(a_line->value, "0 bar")) {
- ast_test_status_update(test, "Find first attribute 'foo' with unspecified payload didn't match\n");
- res = AST_TEST_FAIL;
- }
- idx = ast_sdp_m_find_a_next(m_line, idx, "foo", -1);
- if (idx < 0) {
- ast_test_status_update(test, "Failed to find next attribute 'foo' with unspecified payload\n");
- res = AST_TEST_FAIL;
- goto end;
- }
- a_line = ast_sdp_m_get_a(m_line, idx);
- if (!a_line || strcmp(a_line->value, "0 bee")) {
- ast_test_status_update(test, "Find next attribute 'foo' with unspecified payload didn't match\n");
- res = AST_TEST_FAIL;
- }
- idx = ast_sdp_m_find_a_next(m_line, idx, "foo", -1);
- if (0 <= idx) {
- ast_test_status_update(test, "Find next attribute 'foo' with unspecified payload found too many\n");
- res = AST_TEST_FAIL;
- }
-
- /* These should fail */
- a_line = ast_sdp_m_find_attribute(m_line, "foo", 1);
- if (a_line) {
- ast_test_status_update(test, "Found non-existent attribute 'foo' with payload '1'\n");
- res = AST_TEST_FAIL;
- }
- a_line = ast_sdp_m_find_attribute(m_line, "baz", 0);
- if (a_line) {
- ast_test_status_update(test, "Found non-existent attribute 'baz' with payload '0'\n");
- res = AST_TEST_FAIL;
- }
- a_line = ast_sdp_m_find_attribute(m_line, "wibble", 0);
- if (a_line) {
- ast_test_status_update(test, "Found non-existent attribute 'wibble' with payload '0'\n");
- res = AST_TEST_FAIL;
- }
- a_line = ast_sdp_m_find_attribute(m_line, "wibble", -1);
- if (a_line) {
- ast_test_status_update(test, "Found non-existent attribute 'wibble' with unspecified payload\n");
- res = AST_TEST_FAIL;
- }
-
-end:
- ast_sdp_m_free(m_line);
- return res;
-}
-
-static struct ast_sdp_options *sdp_options_common(void)
-{
- struct ast_sdp_options *options;
-
- options = ast_sdp_options_alloc();
- if (!options) {
- return NULL;
- }
- ast_sdp_options_set_media_address(options, "127.0.0.1");
- ast_sdp_options_set_sdpowner(options, "me");
- ast_sdp_options_set_rtp_engine(options, "asterisk");
- ast_sdp_options_set_impl(options, AST_SDP_IMPL_PJMEDIA);
-
- return options;
-}
-
-struct sdp_format {
- enum ast_media_type type;
- const char *formats;
-};
-
-static int build_sdp_option_formats(struct ast_sdp_options *options, int num_streams, const struct sdp_format *formats)
-{
- int idx;
-
- for (idx = 0; idx < num_streams; ++idx) {
- struct ast_format_cap *caps;
-
- if (ast_strlen_zero(formats[idx].formats)) {
- continue;
- }
-
- caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- if (!caps
- || ast_format_cap_update_by_allow_disallow(caps, formats[idx].formats, 1) < 0) {
- ao2_cleanup(caps);
- return -1;
- }
- ast_sdp_options_set_format_cap_type(options, formats[idx].type, caps);
- ao2_cleanup(caps);
- }
- return 0;
-}
-
-/*!
- * \brief Common method to build an SDP state for a test.
- *
- * This uses the passed-in formats to create a stream topology, which is then used to create the SDP
- * state.
- *
- * There is an optional test_options field you can use if your test has specific options you need to
- * set. If your test does not require anything special, it can just pass NULL for this parameter. If
- * you do pass in test_options, this function steals ownership of those options.
- *
- * \param num_streams The number of elements in the formats array.
- * \param formats Array of media types and formats that will be in the state.
- * \param opt_num_streams The number of new stream types allowed to create.
- * Not used if test_options provided.
- * \param opt_formats Array of new stream media types and formats allowed to create.
- * NULL if use a default stream creation.
- * Not used if test_options provided.
- * \param max_streams 0 if set max to max(3, num_streams) else max(max_streams, num_streams)
- * Not used if test_options provided.
- * \param test_options Optional SDP options.
- */
-static struct ast_sdp_state *build_sdp_state(int num_streams, const struct sdp_format *formats,
- int opt_num_streams, const struct sdp_format *opt_formats, unsigned int max_streams,
- struct ast_sdp_options *test_options)
-{
- struct ast_stream_topology *topology = NULL;
- struct ast_sdp_state *state = NULL;
- struct ast_sdp_options *options;
- int i;
-
- if (!test_options) {
- static const struct sdp_format sdp_formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "ulaw" },
- { AST_MEDIA_TYPE_VIDEO, "vp8" },
- { AST_MEDIA_TYPE_IMAGE, "t38" },
- };
-
- options = sdp_options_common();
- if (!options) {
- goto end;
- }
-
- /* Determine max_streams to allow */
- if (!max_streams) {
- max_streams = ARRAY_LEN(sdp_formats);
- }
- if (max_streams < num_streams) {
- max_streams = num_streams;
- }
- ast_sdp_options_set_max_streams(options, max_streams);
-
- /* Determine new stream formats and types allowed */
- if (!opt_formats) {
- opt_num_streams = ARRAY_LEN(sdp_formats);
- opt_formats = sdp_formats;
- }
- if (build_sdp_option_formats(options, opt_num_streams, opt_formats)) {
- goto end;
- }
- } else {
- options = test_options;
- }
-
- topology = ast_stream_topology_alloc();
- if (!topology) {
- goto end;
- }
-
- for (i = 0; i < num_streams; ++i) {
- struct ast_stream *stream;
-
- stream = ast_stream_alloc("sure_thing", formats[i].type);
- if (!stream) {
- goto end;
- }
- if (!ast_strlen_zero(formats[i].formats)) {
- struct ast_format_cap *caps;
-
- caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- if (!caps
- || ast_format_cap_update_by_allow_disallow(caps, formats[i].formats, 1) < 0) {
- ao2_cleanup(caps);
- ast_stream_free(stream);
- goto end;
- }
- ast_stream_set_formats(stream, caps);
- ao2_cleanup(caps);
- } else {
- ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);
- }
- if (ast_stream_topology_append_stream(topology, stream) < 0) {
- ast_stream_free(stream);
- goto end;
- }
- }
-
- state = ast_sdp_state_alloc(topology, options);
- if (!state) {
- goto end;
- }
-
-end:
- ast_stream_topology_free(topology);
- if (!state) {
- ast_sdp_options_free(options);
- }
-
- return state;
-}
-
-AST_TEST_DEFINE(topology_to_sdp)
-{
- enum ast_test_result_state res = AST_TEST_FAIL;
- struct ast_sdp_state *sdp_state = NULL;
- const struct ast_sdp *sdp = NULL;
- struct ast_sdp_m_line *m_line = NULL;
- struct sdp_format formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "ulaw,alaw,g722,opus" },
- { AST_MEDIA_TYPE_VIDEO, "h264,vp8" },
- { AST_MEDIA_TYPE_IMAGE, "t38" },
- };
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "topology_to_sdp";
- info->category = "/main/sdp/";
- info->summary = "Convert a topology into an SDP";
- info->description =
- "Ensure SDPs get converted to expected stream topology";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- sdp_state = build_sdp_state(ARRAY_LEN(formats), formats,
- ARRAY_LEN(formats), formats, 0, NULL);
- if (!sdp_state) {
- goto end;
- }
-
- sdp = ast_sdp_state_get_local_sdp(sdp_state);
- if (!sdp) {
- goto end;
- }
-
- if (validate_o_line(test, sdp->o_line, "me", "IP4", "127.0.0.1")) {
- goto end;
- }
-
- if (validate_c_line(test, sdp->c_line, "IP4", "127.0.0.1")) {
- goto end;
- }
-
- if (ast_sdp_get_m_count(sdp) != 3) {
- ast_test_status_update(test, "Unexpected number of streams in generated SDP: %d\n",
- ast_sdp_get_m_count(sdp));
- goto end;
- }
-
- m_line = ast_sdp_get_m(sdp, 0);
-
- if (validate_m_line(test, m_line, "audio", 4)) {
- goto end;
- }
-
- if (validate_rtpmap(test, m_line, "PCMU")) {
- goto end;
- }
-
- if (validate_rtpmap(test, m_line, "PCMA")) {
- goto end;
- }
-
- if (validate_rtpmap(test, m_line, "G722")) {
- goto end;
- }
-
- if (validate_rtpmap(test, m_line, "opus")) {
- goto end;
- }
-
- m_line = ast_sdp_get_m(sdp, 1);
- if (validate_m_line(test, m_line, "video", 2)) {
- goto end;
- }
-
- if (validate_rtpmap(test, m_line, "VP8")) {
- goto end;
- }
-
- if (validate_rtpmap(test, m_line, "H264")) {
- goto end;
- }
-
- m_line = ast_sdp_get_m(sdp, 2);
- if (validate_m_line(test, m_line, "image", 1)) {
- goto end;
- }
- if (validate_t38(test, m_line) != AST_TEST_PASS) {
- goto end;
- }
-
- res = AST_TEST_PASS;
-
-end:
- ast_sdp_state_free(sdp_state);
- return res;
-}
-
-static int validate_formats(struct ast_test *test, struct ast_stream_topology *topology, int index,
- enum ast_media_type type, int format_count, const char **expected_formats)
-{
- struct ast_stream *stream;
- struct ast_format_cap *caps;
- struct ast_format *format;
- int i;
-
- stream = ast_stream_topology_get_stream(topology, index);
- if (ast_stream_get_type(stream) != type) {
- ast_test_status_update(test, "Unexpected stream type encountered\n");
- return -1;
- }
- caps = ast_stream_get_formats(stream);
-
- if (ast_format_cap_count(caps) != format_count) {
- ast_test_status_update(test, "Unexpected format count '%d'. Expecting '%d'\n",
- (int) ast_format_cap_count(caps), format_count);
- return -1;
- }
-
- for (i = 0; i < ast_format_cap_count(caps); ++i) {
- format = ast_format_cap_get_format(caps, i);
- if (strcmp(ast_format_get_name(format), expected_formats[i])) {
- ast_test_status_update(test, "Unexpected format '%s'at index %d. Expected '%s'\n",
- ast_format_get_name(format), i, expected_formats[i]);
- return -1;
- }
- }
-
- return 0;
-}
-
-AST_TEST_DEFINE(sdp_to_topology)
-{
- enum ast_test_result_state res = AST_TEST_PASS;
- struct ast_sdp_state *sdp_state;
- const struct ast_sdp *sdp;
- struct ast_stream_topology *topology = NULL;
- struct sdp_format sdp_formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "ulaw,alaw,g722,opus" },
- { AST_MEDIA_TYPE_VIDEO, "h264,vp8" },
- { AST_MEDIA_TYPE_IMAGE, "t38" },
- };
- static const char *expected_audio_formats[] = {
- "ulaw",
- "alaw",
- "g722",
- "opus",
- };
- static const char *expected_video_formats[] = {
- "h264",
- "vp8",
- };
- static const char *expected_image_formats[] = {
- "t38",
- };
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "sdp_to_topology";
- info->category = "/main/sdp/";
- info->summary = "Convert an SDP into a topology";
- info->description =
- "Ensure SDPs get converted to expected stream topology";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- sdp_state = build_sdp_state(ARRAY_LEN(sdp_formats), sdp_formats,
- ARRAY_LEN(sdp_formats), sdp_formats, 0, NULL);
- if (!sdp_state) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
- sdp = ast_sdp_state_get_local_sdp(sdp_state);
- if (!sdp) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
- topology = ast_get_topology_from_sdp(sdp, 0);
- if (!topology) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
- if (ast_stream_topology_get_count(topology) != 3) {
- ast_test_status_update(test, "Unexpected topology count '%d'. Expecting 3\n",
- ast_stream_topology_get_count(topology));
- res = AST_TEST_FAIL;
- goto end;
- }
-
- if (validate_formats(test, topology, 0, AST_MEDIA_TYPE_AUDIO,
- ARRAY_LEN(expected_audio_formats), expected_audio_formats)) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
- if (validate_formats(test, topology, 1, AST_MEDIA_TYPE_VIDEO,
- ARRAY_LEN(expected_video_formats), expected_video_formats)) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
- if (validate_formats(test, topology, 2, AST_MEDIA_TYPE_IMAGE,
- ARRAY_LEN(expected_image_formats), expected_image_formats)) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
-end:
- ast_sdp_state_free(sdp_state);
- ast_stream_topology_free(topology);
- return res;
-}
-
-static int validate_avi_sdp_streams(struct ast_test *test, const struct ast_sdp *sdp)
-{
- struct ast_sdp_m_line *m_line;
-
- if (!sdp) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 0);
- if (validate_m_line(test, m_line, "audio", 1)) {
- return -1;
- }
- if (validate_rtpmap(test, m_line, "PCMU")) {
- return -1;
- }
-
- /* The other audio formats should *NOT* be present */
- if (!validate_rtpmap(test, m_line, "PCMA")) {
- return -1;
- }
- if (!validate_rtpmap(test, m_line, "G722")) {
- return -1;
- }
- if (!validate_rtpmap(test, m_line, "opus")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 1);
- if (validate_m_line(test, m_line, "video", 1)) {
- return -1;
- }
- if (validate_rtpmap(test, m_line, "VP8")) {
- return -1;
- }
- if (!validate_rtpmap(test, m_line, "H264")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 2);
- if (validate_m_line(test, m_line, "image", 1)) {
- return -1;
- }
-
- return 0;
-}
-
-static enum ast_test_result_state sdp_negotiation_completed_tests(struct ast_test *test,
- int offer_num_streams, const struct sdp_format *offer_formats,
- int answer_num_streams, const struct sdp_format *answer_formats,
- int allowed_ans_num_streams, const struct sdp_format *allowed_ans_formats,
- unsigned int max_streams,
- int (*validate_sdp)(struct ast_test *test, const struct ast_sdp *sdp))
-{
- enum ast_test_result_state res = AST_TEST_PASS;
- struct ast_sdp_state *sdp_state_offerer = NULL;
- struct ast_sdp_state *sdp_state_answerer = NULL;
- const struct ast_sdp *offerer_sdp;
- const struct ast_sdp *answerer_sdp;
-
- sdp_state_offerer = build_sdp_state(offer_num_streams, offer_formats,
- offer_num_streams, offer_formats, max_streams, NULL);
- if (!sdp_state_offerer) {
- ast_test_status_update(test, "Building offerer SDP state failed\n");
- res = AST_TEST_FAIL;
- goto end;
- }
-
- sdp_state_answerer = build_sdp_state(answer_num_streams, answer_formats,
- allowed_ans_num_streams, allowed_ans_formats, max_streams, NULL);
- if (!sdp_state_answerer) {
- ast_test_status_update(test, "Building answerer SDP state failed\n");
- res = AST_TEST_FAIL;
- goto end;
- }
-
- offerer_sdp = ast_sdp_state_get_local_sdp(sdp_state_offerer);
- if (!offerer_sdp) {
- ast_test_status_update(test, "Building offerer offer failed\n");
- res = AST_TEST_FAIL;
- goto end;
- }
-
- if (ast_sdp_state_set_remote_sdp(sdp_state_answerer, offerer_sdp)) {
- ast_test_status_update(test, "Setting answerer offer failed\n");
- res = AST_TEST_FAIL;
- goto end;
- }
- answerer_sdp = ast_sdp_state_get_local_sdp(sdp_state_answerer);
- if (!answerer_sdp) {
- ast_test_status_update(test, "Building answerer answer failed\n");
- res = AST_TEST_FAIL;
- goto end;
- }
-
- if (ast_sdp_state_set_remote_sdp(sdp_state_offerer, answerer_sdp)) {
- ast_test_status_update(test, "Setting offerer answer failed\n");
- res = AST_TEST_FAIL;
- goto end;
- }
-
- /*
- * Restart SDP negotiations to build the joint SDP on the offerer
- * side. Otherwise we will get the original offer for use in
- * case of retransmissions.
- */
- if (ast_sdp_state_restart_negotiations(sdp_state_offerer)) {
- ast_test_status_update(test, "Restarting negotiations failed\n");
- res = AST_TEST_FAIL;
- goto end;
- }
- offerer_sdp = ast_sdp_state_get_local_sdp(sdp_state_offerer);
- if (!offerer_sdp) {
- ast_test_status_update(test, "Building offerer current sdp failed\n");
- res = AST_TEST_FAIL;
- goto end;
- }
- if (validate_sdp(test, offerer_sdp)) {
- res = AST_TEST_FAIL;
- goto end;
- }
- if (validate_sdp(test, answerer_sdp)) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
-end:
- ast_sdp_state_free(sdp_state_offerer);
- ast_sdp_state_free(sdp_state_answerer);
-
- return res;
-}
-
-AST_TEST_DEFINE(sdp_negotiation_initial)
-{
- static const struct sdp_format offerer_formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "ulaw,alaw,g722,opus" },
- { AST_MEDIA_TYPE_VIDEO, "h264,vp8" },
- { AST_MEDIA_TYPE_IMAGE, "t38" },
- };
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "sdp_negotiation_initial";
- info->category = "/main/sdp/";
- info->summary = "Simulate an initial negotiation";
- info->description =
- "Initial negotiation tests creating new streams on the answering side.\n"
- "After negotiation both offerer and answerer sides should have the same\n"
- "expected stream types and formats.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- return sdp_negotiation_completed_tests(test,
- ARRAY_LEN(offerer_formats), offerer_formats,
- 0, NULL,
- 0, NULL,
- 0,
- validate_avi_sdp_streams);
-}
-
-AST_TEST_DEFINE(sdp_negotiation_type_change)
-{
- static const struct sdp_format offerer_formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "ulaw,alaw,g722,opus" },
- { AST_MEDIA_TYPE_VIDEO, "h264,vp8" },
- { AST_MEDIA_TYPE_IMAGE, "t38" },
- };
- static const struct sdp_format answerer_formats[] = {
- { AST_MEDIA_TYPE_IMAGE, "t38" },
- { AST_MEDIA_TYPE_VIDEO, "vp8" },
- { AST_MEDIA_TYPE_AUDIO, "ulaw" },
- };
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "sdp_negotiation_type_change";
- info->category = "/main/sdp/";
- info->summary = "Simulate a re-negotiation changing stream types";
- info->description =
- "Reinvite negotiation tests changing stream types on the answering side.\n"
- "After negotiation both offerer and answerer sides should have the same\n"
- "expected stream types and formats.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- return sdp_negotiation_completed_tests(test,
- ARRAY_LEN(offerer_formats), offerer_formats,
- ARRAY_LEN(answerer_formats), answerer_formats,
- 0, NULL,
- 0,
- validate_avi_sdp_streams);
-}
-
-static int validate_aviavia_declined_sdp_streams(struct ast_test *test, const struct ast_sdp *sdp)
-{
- struct ast_sdp_m_line *m_line;
-
- if (!sdp) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 0);
- if (validate_m_line_declined(test, m_line, "audio")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 1);
- if (validate_m_line_declined(test, m_line, "video")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 2);
- if (validate_m_line_declined(test, m_line, "image")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 3);
- if (validate_m_line_declined(test, m_line, "audio")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 4);
- if (validate_m_line_declined(test, m_line, "video")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 5);
- if (validate_m_line_declined(test, m_line, "image")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 6);
- if (validate_m_line(test, m_line, "audio", 1)) {
- return -1;
- }
- if (validate_rtpmap(test, m_line, "PCMU")) {
- return -1;
- }
-
- /* The other audio formats should *NOT* be present */
- if (!validate_rtpmap(test, m_line, "PCMA")) {
- return -1;
- }
-
- return 0;
-}
-
-AST_TEST_DEFINE(sdp_negotiation_decline_incompatible)
-{
- static const struct sdp_format offerer_formats[] = {
- /* Incompatible declined streams */
- { AST_MEDIA_TYPE_AUDIO, "alaw" },
- { AST_MEDIA_TYPE_VIDEO, "vp8" },
- { AST_MEDIA_TYPE_IMAGE, "t38" },
- /* Initially declined streams */
- { AST_MEDIA_TYPE_AUDIO, "" },
- { AST_MEDIA_TYPE_VIDEO, "" },
- { AST_MEDIA_TYPE_IMAGE, "" },
- /* Compatible stream so not all are declined */
- { AST_MEDIA_TYPE_AUDIO, "ulaw,alaw" },
- };
- static const struct sdp_format allowed_formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "ulaw" },
- };
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "sdp_negotiation_decline_incompatible";
- info->category = "/main/sdp/";
- info->summary = "Simulate an initial negotiation declining streams";
- info->description =
- "Initial negotiation tests declining incompatible streams.\n"
- "After negotiation both offerer and answerer sides should have\n"
- "the same expected stream types and formats.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- return sdp_negotiation_completed_tests(test,
- ARRAY_LEN(offerer_formats), offerer_formats,
- 0, NULL,
- ARRAY_LEN(allowed_formats), allowed_formats,
- ARRAY_LEN(offerer_formats),
- validate_aviavia_declined_sdp_streams);
-}
-
-static int validate_aaaa_declined_sdp_streams(struct ast_test *test, const struct ast_sdp *sdp)
-{
- struct ast_sdp_m_line *m_line;
-
- if (!sdp) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 0);
- if (validate_m_line(test, m_line, "audio", 1)) {
- return -1;
- }
- if (validate_rtpmap(test, m_line, "PCMU")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 1);
- if (validate_m_line(test, m_line, "audio", 1)) {
- return -1;
- }
- if (validate_rtpmap(test, m_line, "PCMU")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 2);
- if (validate_m_line(test, m_line, "audio", 1)) {
- return -1;
- }
- if (validate_rtpmap(test, m_line, "PCMU")) {
- return -1;
- }
-
- m_line = ast_sdp_get_m(sdp, 3);
- if (validate_m_line_declined(test, m_line, "audio")) {
- return -1;
- }
-
- return 0;
-}
-
-AST_TEST_DEFINE(sdp_negotiation_decline_max_streams)
-{
- static const struct sdp_format offerer_formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "ulaw" },
- { AST_MEDIA_TYPE_AUDIO, "ulaw" },
- { AST_MEDIA_TYPE_AUDIO, "ulaw" },
- { AST_MEDIA_TYPE_AUDIO, "ulaw" },
- };
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "sdp_negotiation_decline_max_streams";
- info->category = "/main/sdp/";
- info->summary = "Simulate an initial negotiation declining excessive streams";
- info->description =
- "Initial negotiation tests declining too many streams on the answering side.\n"
- "After negotiation both offerer and answerer sides should have the same\n"
- "expected stream types and formats.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- return sdp_negotiation_completed_tests(test,
- ARRAY_LEN(offerer_formats), offerer_formats,
- 0, NULL,
- 0, NULL,
- 0,
- validate_aaaa_declined_sdp_streams);
-}
-
-AST_TEST_DEFINE(sdp_negotiation_not_acceptable)
-{
- enum ast_test_result_state res = AST_TEST_PASS;
- struct ast_sdp_state *sdp_state_offerer = NULL;
- struct ast_sdp_state *sdp_state_answerer = NULL;
- const struct ast_sdp *offerer_sdp;
-
- static const struct sdp_format offerer_formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "alaw" },
- { AST_MEDIA_TYPE_AUDIO, "alaw" },
- };
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "sdp_negotiation_not_acceptable";
- info->category = "/main/sdp/";
- info->summary = "Simulate an initial negotiation declining all streams";
- info->description =
- "Initial negotiation tests declining all streams for a 488 on the answering side.\n"
- "Negotiations should fail because there are no acceptable streams.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- sdp_state_offerer = build_sdp_state(ARRAY_LEN(offerer_formats), offerer_formats,
- ARRAY_LEN(offerer_formats), offerer_formats, 0, NULL);
- if (!sdp_state_offerer) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
- sdp_state_answerer = build_sdp_state(0, NULL, 0, NULL, 0, NULL);
- if (!sdp_state_answerer) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
- offerer_sdp = ast_sdp_state_get_local_sdp(sdp_state_offerer);
- if (!offerer_sdp) {
- res = AST_TEST_FAIL;
- goto end;
- }
-
- if (!ast_sdp_state_set_remote_sdp(sdp_state_answerer, offerer_sdp)) {
- ast_test_status_update(test, "Bad. Setting remote SDP was successful.\n");
- res = AST_TEST_FAIL;
- goto end;
- }
- if (!ast_sdp_state_is_offer_rejected(sdp_state_answerer)) {
- ast_test_status_update(test, "Bad. Negotiation failed for some other reason.\n");
- res = AST_TEST_FAIL;
- goto end;
- }
-
-end:
- ast_sdp_state_free(sdp_state_offerer);
- ast_sdp_state_free(sdp_state_answerer);
-
- return res;
-}
-
-static int validate_ssrc(struct ast_test *test, struct ast_sdp_m_line *m_line,
- struct ast_rtp_instance *rtp)
-{
- unsigned int ssrc;
- const char *cname;
- struct ast_sdp_a_line *a_line;
- char attr_value[128];
-
- ssrc = ast_rtp_instance_get_ssrc(rtp);
- cname = ast_rtp_instance_get_cname(rtp);
-
- snprintf(attr_value, sizeof(attr_value), "%u cname:%s", ssrc, cname);
-
- a_line = ast_sdp_m_find_attribute(m_line, "ssrc", -1);
- if (!a_line) {
- ast_test_status_update(test, "Could not find 'ssrc' attribute\n");
- return -1;
- }
-
- if (strcmp(a_line->value, attr_value)) {
- ast_test_status_update(test, "SDP attribute '%s' did not match expected attribute '%s'\n",
- a_line->value, attr_value);
- return -1;
- }
-
- return 0;
-}
-
-AST_TEST_DEFINE(sdp_ssrc_attributes)
-{
- enum ast_test_result_state res;
- struct ast_sdp_state *test_state = NULL;
- struct ast_sdp_options *options;
- struct sdp_format formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "ulaw,alaw,g722,opus" },
- };
- const struct ast_sdp *sdp;
- struct ast_sdp_m_line *m_line;
- struct ast_rtp_instance *rtp;
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "sdp_ssrc_attributes";
- info->category = "/main/sdp/";
- info->summary = "Ensure SSRC-level attributes are added to local SDPs";
- info->description =
- "An SDP is created and is instructed to include SSRC-level attributes.\n"
- "This test ensures that the CNAME SSRC-level attribute is present and\n"
- "that the values match what the RTP instance reports";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- res = AST_TEST_FAIL;
-
- options = sdp_options_common();
- if (!options) {
- ast_test_status_update(test, "Failed to allocate SDP options\n");
- goto end;
- }
- if (build_sdp_option_formats(options, ARRAY_LEN(formats), formats)) {
- goto end;
- }
- ast_sdp_options_set_ssrc(options, 1);
-
- test_state = build_sdp_state(ARRAY_LEN(formats), formats, 0, NULL, 0, options);
- if (!test_state) {
- ast_test_status_update(test, "Failed to create SDP state\n");
- goto end;
- }
-
- sdp = ast_sdp_state_get_local_sdp(test_state);
- if (!sdp) {
- ast_test_status_update(test, "Failed to get local SDP\n");
- goto end;
- }
-
- /* Need a couple of sanity checks */
- if (ast_sdp_get_m_count(sdp) != ARRAY_LEN(formats)) {
- ast_test_status_update(test, "SDP m count is %d instead of %zu\n",
- ast_sdp_get_m_count(sdp), ARRAY_LEN(formats));
- goto end;
- }
-
- m_line = ast_sdp_get_m(sdp, 0);
- if (!m_line) {
- ast_test_status_update(test, "Failed to get SDP m-line\n");
- goto end;
- }
-
- rtp = ast_sdp_state_get_rtp_instance(test_state, 0);
- if (!rtp) {
- ast_test_status_update(test, "Failed to get the RTP instance\n");
- goto end;
- }
-
- if (validate_ssrc(test, m_line, rtp)) {
- goto end;
- }
-
- res = AST_TEST_PASS;
-
-end:
- ast_sdp_state_free(test_state);
- return res;
-}
-
-struct sdp_topology_stream {
- /*! Media stream type: audio, video, image */
- enum ast_media_type type;
- /*! Media stream state: removed/declined, sendrecv */
- enum ast_stream_state state;
- /*! Comma separated list of formats allowed on the stream. Can be NULL if stream is removed/declined. */
- const char *formats;
- /*! Optional name of stream. NULL for default name. */
- const char *name;
-};
-
-struct sdp_update_test {
- /*! Maximum number of streams. (0 if default) */
- int max_streams;
- /*! Optional initial SDP state topology (NULL if not present) */
- const struct sdp_topology_stream * const *initial;
- /*! Required first topology update */
- const struct sdp_topology_stream * const *update_1;
- /*! Optional second topology update (NULL if not present) */
- const struct sdp_topology_stream * const *update_2;
- /*! Expected topology to be offered */
- const struct sdp_topology_stream * const *expected;
-};
-
-static struct ast_stream_topology *build_update_topology(const struct sdp_topology_stream * const *spec)
-{
- struct ast_stream_topology *topology;
- const struct sdp_topology_stream *desc;
-
- topology = ast_stream_topology_alloc();
- if (!topology) {
- return NULL;
- }
-
- for (desc = *spec; desc; ++spec, desc = *spec) {
- struct ast_stream *stream;
- const char *name;
-
- name = desc->name ?: ast_codec_media_type2str(desc->type);
- stream = ast_stream_alloc(name, desc->type);
- if (!stream) {
- goto fail;
- }
- ast_stream_set_state(stream, desc->state);
- if (desc->formats) {
- struct ast_format_cap *caps;
-
- caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
- if (!caps
- || ast_format_cap_update_by_allow_disallow(caps, desc->formats, 1) < 0) {
- ao2_cleanup(caps);
- ast_stream_free(stream);
- goto fail;
- }
- ast_stream_set_formats(stream, caps);
- ao2_ref(caps, -1);
- }
- if (ast_stream_topology_append_stream(topology, stream) < 0) {
- ast_stream_free(stream);
- goto fail;
- }
- }
- return topology;
-
-fail:
- ast_stream_topology_free(topology);
- return NULL;
-}
-
-static int cmp_update_topology(struct ast_test *test,
- const struct ast_stream_topology *expected, const struct ast_stream_topology *merged)
-{
- int status = 0;
- int idx;
- int max_streams;
- struct ast_stream *exp_stream;
- struct ast_stream *mrg_stream;
-
- idx = ast_stream_topology_get_count(expected);
- max_streams = ast_stream_topology_get_count(merged);
- if (idx != max_streams) {
- ast_test_status_update(test, "Expected %d streams got %d streams\n",
- idx, max_streams);
- status = -1;
- }
- if (idx < max_streams) {
- max_streams = idx;
- }
-
- /* Compare common streams by position */
- for (idx = 0; idx < max_streams; ++idx) {
- exp_stream = ast_stream_topology_get_stream(expected, idx);
- mrg_stream = ast_stream_topology_get_stream(merged, idx);
-
- if (strcmp(ast_stream_get_name(exp_stream), ast_stream_get_name(mrg_stream))) {
- ast_test_status_update(test,
- "Stream %d: Expected stream name '%s' got stream name '%s'\n",
- idx,
- ast_stream_get_name(exp_stream),
- ast_stream_get_name(mrg_stream));
- status = -1;
- }
-
- if (ast_stream_get_state(exp_stream) != ast_stream_get_state(mrg_stream)) {
- ast_test_status_update(test,
- "Stream %d: Expected stream state '%s' got stream state '%s'\n",
- idx,
- ast_stream_state2str(ast_stream_get_state(exp_stream)),
- ast_stream_state2str(ast_stream_get_state(mrg_stream)));
- status = -1;
- }
-
- if (ast_stream_get_type(exp_stream) != ast_stream_get_type(mrg_stream)) {
- ast_test_status_update(test,
- "Stream %d: Expected stream type '%s' got stream type '%s'\n",
- idx,
- ast_codec_media_type2str(ast_stream_get_type(exp_stream)),
- ast_codec_media_type2str(ast_stream_get_type(mrg_stream)));
- status = -1;
- continue;
- }
-
- if (ast_stream_get_state(exp_stream) == AST_STREAM_STATE_REMOVED
- || ast_stream_get_state(mrg_stream) == AST_STREAM_STATE_REMOVED) {
- /*
- * Cannot compare formats if one of the streams is
- * declined because there may not be any on the declined
- * stream.
- */
- continue;
- }
- if (!ast_format_cap_identical(ast_stream_get_formats(exp_stream),
- ast_stream_get_formats(mrg_stream))) {
- ast_test_status_update(test,
- "Stream %d: Expected formats do not match merged formats\n",
- idx);
- status = -1;
- }
- }
-
- return status;
-}
-
-
-static const struct sdp_topology_stream audio_declined_no_name = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_REMOVED, NULL, NULL
-};
-
-static const struct sdp_topology_stream audio_ulaw_no_name = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "ulaw", NULL
-};
-
-static const struct sdp_topology_stream audio_alaw_no_name = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "alaw", NULL
-};
-
-static const struct sdp_topology_stream audio_g722_no_name = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "g722", NULL
-};
-
-static const struct sdp_topology_stream audio_g723_no_name = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "g723", NULL
-};
-
-static const struct sdp_topology_stream video_declined_no_name = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_REMOVED, NULL, NULL
-};
-
-static const struct sdp_topology_stream video_h261_no_name = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "h261", NULL
-};
-
-static const struct sdp_topology_stream video_h263_no_name = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "h263", NULL
-};
-
-static const struct sdp_topology_stream video_h264_no_name = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "h264", NULL
-};
-
-static const struct sdp_topology_stream video_vp8_no_name = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "vp8", NULL
-};
-
-static const struct sdp_topology_stream image_declined_no_name = {
- AST_MEDIA_TYPE_IMAGE, AST_STREAM_STATE_REMOVED, NULL, NULL
-};
-
-static const struct sdp_topology_stream image_t38_no_name = {
- AST_MEDIA_TYPE_IMAGE, AST_STREAM_STATE_SENDRECV, "t38", NULL
-};
-
-
-static const struct sdp_topology_stream *top_ulaw_alaw_h264__vp8[] = {
- &audio_ulaw_no_name,
- &audio_alaw_no_name,
- &video_h264_no_name,
- &video_vp8_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top__vp8_alaw_h264_ulaw[] = {
- &video_vp8_no_name,
- &audio_alaw_no_name,
- &video_h264_no_name,
- &audio_ulaw_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_alaw_ulaw__vp8_h264[] = {
- &audio_alaw_no_name,
- &audio_ulaw_no_name,
- &video_vp8_no_name,
- &video_h264_no_name,
- NULL
-};
-
-/* Sorting by type with no new or deleted streams */
-static const struct sdp_update_test mrg_by_type_00 = {
- .initial = top_ulaw_alaw_h264__vp8,
- .update_1 = top__vp8_alaw_h264_ulaw,
- .expected = top_alaw_ulaw__vp8_h264,
-};
-
-
-static const struct sdp_topology_stream *top_alaw__vp8[] = {
- &audio_alaw_no_name,
- &video_vp8_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_h264__vp8_ulaw[] = {
- &video_h264_no_name,
- &video_vp8_no_name,
- &audio_ulaw_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_ulaw_h264__vp8[] = {
- &audio_ulaw_no_name,
- &video_h264_no_name,
- &video_vp8_no_name,
- NULL
-};
-
-/* Sorting by type and adding a stream */
-static const struct sdp_update_test mrg_by_type_01 = {
- .initial = top_alaw__vp8,
- .update_1 = top_h264__vp8_ulaw,
- .expected = top_ulaw_h264__vp8,
-};
-
-
-static const struct sdp_topology_stream *top_alaw__vp8_vdec[] = {
- &audio_alaw_no_name,
- &video_vp8_no_name,
- &video_declined_no_name,
- NULL
-};
-
-/* Sorting by type and deleting a stream */
-static const struct sdp_update_test mrg_by_type_02 = {
- .initial = top_ulaw_h264__vp8,
- .update_1 = top_alaw__vp8,
- .expected = top_alaw__vp8_vdec,
-};
-
-
-static const struct sdp_topology_stream *top_h264_alaw_ulaw[] = {
- &video_h264_no_name,
- &audio_alaw_no_name,
- &audio_ulaw_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top__t38[] = {
- &image_t38_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_vdec__t38_adec[] = {
- &video_declined_no_name,
- &image_t38_no_name,
- &audio_declined_no_name,
- NULL
-};
-
-/* Sorting by type changing stream types for T.38 */
-static const struct sdp_update_test mrg_by_type_03 = {
- .initial = top_h264_alaw_ulaw,
- .update_1 = top__t38,
- .expected = top_vdec__t38_adec,
-};
-
-
-/* Sorting by type changing stream types back from T.38 */
-static const struct sdp_update_test mrg_by_type_04 = {
- .initial = top_vdec__t38_adec,
- .update_1 = top_h264_alaw_ulaw,
- .expected = top_h264_alaw_ulaw,
-};
-
-
-static const struct sdp_topology_stream *top_h264[] = {
- &video_h264_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_vdec__t38[] = {
- &video_declined_no_name,
- &image_t38_no_name,
- NULL
-};
-
-/* Sorting by type changing stream types for T.38 */
-static const struct sdp_update_test mrg_by_type_05 = {
- .initial = top_h264,
- .update_1 = top__t38,
- .expected = top_vdec__t38,
-};
-
-
-static const struct sdp_topology_stream *top_h264_idec[] = {
- &video_h264_no_name,
- &image_declined_no_name,
- NULL
-};
-
-/* Sorting by type changing stream types back from T.38 */
-static const struct sdp_update_test mrg_by_type_06 = {
- .initial = top_vdec__t38,
- .update_1 = top_h264,
- .expected = top_h264_idec,
-};
-
-
-static const struct sdp_topology_stream *top_ulaw_adec_h264__vp8[] = {
- &audio_ulaw_no_name,
- &audio_declined_no_name,
- &video_h264_no_name,
- &video_vp8_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_h263_alaw_h261_h264_vp8[] = {
- &video_h263_no_name,
- &audio_alaw_no_name,
- &video_h261_no_name,
- &video_h264_no_name,
- &video_vp8_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_alaw_h264_h263_h261_vp8[] = {
- &audio_alaw_no_name,
- &video_h264_no_name,
- &video_h263_no_name,
- &video_h261_no_name,
- &video_vp8_no_name,
- NULL
-};
-
-/* Sorting by type with backfill and adding streams */
-static const struct sdp_update_test mrg_by_type_07 = {
- .initial = top_ulaw_adec_h264__vp8,
- .update_1 = top_h263_alaw_h261_h264_vp8,
- .expected = top_alaw_h264_h263_h261_vp8,
-};
-
-
-static const struct sdp_topology_stream *top_ulaw_alaw_h264__vp8_h261[] = {
- &audio_ulaw_no_name,
- &audio_alaw_no_name,
- &video_h264_no_name,
- &video_vp8_no_name,
- &video_h261_no_name,
- NULL
-};
-
-/* Sorting by type overlimit of 4 and drop */
-static const struct sdp_update_test mrg_by_type_08 = {
- .max_streams = 4,
- .initial = top_ulaw_alaw_h264__vp8,
- .update_1 = top_ulaw_alaw_h264__vp8_h261,
- .expected = top_ulaw_alaw_h264__vp8,
-};
-
-
-static const struct sdp_topology_stream *top_ulaw_alaw_h264[] = {
- &audio_ulaw_no_name,
- &audio_alaw_no_name,
- &video_h264_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_alaw_h261__vp8[] = {
- &audio_alaw_no_name,
- &video_h261_no_name,
- &video_vp8_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_alaw_adec_h261__vp8[] = {
- &audio_alaw_no_name,
- &audio_declined_no_name,
- &video_h261_no_name,
- &video_vp8_no_name,
- NULL
-};
-
-/* Sorting by type with delete and add of streams */
-static const struct sdp_update_test mrg_by_type_09 = {
- .initial = top_ulaw_alaw_h264,
- .update_1 = top_alaw_h261__vp8,
- .expected = top_alaw_adec_h261__vp8,
-};
-
-
-static const struct sdp_topology_stream *top_ulaw_adec_h264[] = {
- &audio_ulaw_no_name,
- &audio_declined_no_name,
- &video_h264_no_name,
- NULL
-};
-
-/* Sorting by type and adding streams */
-static const struct sdp_update_test mrg_by_type_10 = {
- .initial = top_ulaw_adec_h264,
- .update_1 = top_alaw_ulaw__vp8_h264,
- .expected = top_alaw_ulaw__vp8_h264,
-};
-
-
-static const struct sdp_topology_stream *top_adec_g722_h261[] = {
- &audio_declined_no_name,
- &audio_g722_no_name,
- &video_h261_no_name,
- NULL
-};
-
-/* Sorting by type and deleting old streams */
-static const struct sdp_update_test mrg_by_type_11 = {
- .initial = top_ulaw_alaw_h264,
- .update_1 = top_adec_g722_h261,
- .expected = top_adec_g722_h261,
-};
-
-
-static const struct sdp_topology_stream audio_alaw4dave = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "alaw", "dave"
-};
-
-static const struct sdp_topology_stream audio_g7224dave = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "g722", "dave"
-};
-
-static const struct sdp_topology_stream audio_ulaw4fred = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "ulaw", "fred"
-};
-
-static const struct sdp_topology_stream audio_alaw4fred = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "alaw", "fred"
-};
-
-static const struct sdp_topology_stream audio_ulaw4rose = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "ulaw", "rose"
-};
-
-static const struct sdp_topology_stream audio_g7224rose = {
- AST_MEDIA_TYPE_AUDIO, AST_STREAM_STATE_SENDRECV, "g722", "rose"
-};
-
-
-static const struct sdp_topology_stream video_h2614dave = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "h261", "dave"
-};
-
-static const struct sdp_topology_stream video_h2634dave = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "h263", "dave"
-};
-
-static const struct sdp_topology_stream video_h2634fred = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "h263", "fred"
-};
-
-static const struct sdp_topology_stream video_h2644fred = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "h264", "fred"
-};
-
-static const struct sdp_topology_stream video_h2644rose = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "h264", "rose"
-};
-
-static const struct sdp_topology_stream video_h2614rose = {
- AST_MEDIA_TYPE_VIDEO, AST_STREAM_STATE_SENDRECV, "h261", "rose"
-};
-
-
-static const struct sdp_topology_stream *top_adave_alaw_afred_ulaw_arose_g722_vdave_h261_vfred_h263_vrose_h264[] = {
- &audio_alaw4dave,
- &audio_alaw_no_name,
- &audio_ulaw4fred,
- &audio_ulaw_no_name,
- &audio_g7224rose,
- &audio_g722_no_name,
- &video_h2614dave,
- &video_h261_no_name,
- &video_h2634fred,
- &video_h263_no_name,
- &video_h2644rose,
- &video_h264_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_vfred_vrose_vdave_h263_h264_h261_afred_ulaw_arose_g722_adave_alaw[] = {
- &video_h2644fred,
- &video_h2614rose,
- &video_h2634dave,
- &video_h263_no_name,
- &video_h264_no_name,
- &video_h261_no_name,
- &audio_alaw4fred,
- &audio_ulaw_no_name,
- &audio_ulaw4rose,
- &audio_g722_no_name,
- &audio_g7224dave,
- &audio_alaw_no_name,
- NULL
-};
-
-static const struct sdp_topology_stream *top_adave_ulaw_afred_g722_arose_alaw_vdave_h263_vfred_h264_vrose_h261[] = {
- &audio_g7224dave,
- &audio_ulaw_no_name,
- &audio_alaw4fred,
- &audio_g722_no_name,
- &audio_ulaw4rose,
- &audio_alaw_no_name,
- &video_h2634dave,
- &video_h263_no_name,
- &video_h2644fred,
- &video_h264_no_name,
- &video_h2614rose,
- &video_h261_no_name,
- NULL
-};
-
-/* Sorting by name and type with no new or deleted streams */
-static const struct sdp_update_test mrg_by_name_00 = {
- .initial = top_adave_alaw_afred_ulaw_arose_g722_vdave_h261_vfred_h263_vrose_h264,
- .update_1 = top_vfred_vrose_vdave_h263_h264_h261_afred_ulaw_arose_g722_adave_alaw,
- .expected = top_adave_ulaw_afred_g722_arose_alaw_vdave_h263_vfred_h264_vrose_h261,
-};
-
-
-static const struct sdp_topology_stream *top_adave_g723_h261[] = {
- &audio_g7224dave,
- &audio_g723_no_name,
- &video_h261_no_name,
- NULL
-};
-
-/* Sorting by name and type adding names to streams */
-static const struct sdp_update_test mrg_by_name_01 = {
- .initial = top_ulaw_alaw_h264,
- .update_1 = top_adave_g723_h261,
- .expected = top_adave_g723_h261,
-};
-
-
-/* Sorting by name and type removing names from streams */
-static const struct sdp_update_test mrg_by_name_02 = {
- .initial = top_adave_g723_h261,
- .update_1 = top_ulaw_alaw_h264,
- .expected = top_ulaw_alaw_h264,
-};
-
-
-static const struct sdp_update_test *sdp_update_cases[] = {
- /* Merging by type */
- /* 00 */ &mrg_by_type_00,
- /* 01 */ &mrg_by_type_01,
- /* 02 */ &mrg_by_type_02,
- /* 03 */ &mrg_by_type_03,
- /* 04 */ &mrg_by_type_04,
- /* 05 */ &mrg_by_type_05,
- /* 06 */ &mrg_by_type_06,
- /* 07 */ &mrg_by_type_07,
- /* 08 */ &mrg_by_type_08,
- /* 09 */ &mrg_by_type_09,
- /* 10 */ &mrg_by_type_10,
- /* 11 */ &mrg_by_type_11,
-
- /* Merging by name and type */
- /* 12 */ &mrg_by_name_00,
- /* 13 */ &mrg_by_name_01,
- /* 14 */ &mrg_by_name_02,
-};
-
-AST_TEST_DEFINE(sdp_update_topology)
-{
- enum ast_test_result_state res;
- unsigned int idx;
- int status;
- struct ast_sdp_options *options;
- struct ast_stream_topology *topology;
- struct ast_sdp_state *test_state = NULL;
-
- static const struct sdp_format sdp_formats[] = {
- { AST_MEDIA_TYPE_AUDIO, "ulaw,alaw,g722,g723" },
- { AST_MEDIA_TYPE_VIDEO, "h261,h263,h264,vp8" },
- { AST_MEDIA_TYPE_IMAGE, "t38" },
- };
-
- switch(cmd) {
- case TEST_INIT:
- info->name = "sdp_update_topology";
- info->category = "/main/sdp/";
- info->summary = "Merge topology updates from the system";
- info->description =
- "1) Create a SDP state with an optional initial topology.\n"
- "2) Update the initial topology with one or two new topologies.\n"
- "3) Get the SDP offer to merge the updates into the initial topology.\n"
- "4) Check that the offered topology matches the expected topology.\n"
- "5) Repeat these steps for each test case defined.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
-
- res = AST_TEST_FAIL;
- for (idx = 0; idx < ARRAY_LEN(sdp_update_cases); ++idx) {
- ast_test_status_update(test, "Starting update case %d\n", idx);
-
- /* Create a SDP state with an optional initial topology. */
- options = sdp_options_common();
- if (!options) {
- ast_test_status_update(test, "Failed to allocate SDP options\n");
- goto end;
- }
- if (sdp_update_cases[idx]->max_streams) {
- ast_sdp_options_set_max_streams(options, sdp_update_cases[idx]->max_streams);
- }
- if (build_sdp_option_formats(options, ARRAY_LEN(sdp_formats), sdp_formats)) {
- ast_test_status_update(test, "Failed to setup SDP options new stream formats\n");
- goto end;
- }
- if (sdp_update_cases[idx]->initial) {
- topology = build_update_topology(sdp_update_cases[idx]->initial);
- if (!topology) {
- ast_test_status_update(test, "Failed to build initial SDP state topology\n");
- goto end;
- }
- } else {
- topology = NULL;
- }
- test_state = ast_sdp_state_alloc(topology, options);
- ast_stream_topology_free(topology);
- if (!test_state) {
- ast_test_status_update(test, "Failed to build SDP state\n");
- goto end;
- }
-
- /* Update the initial topology with one or two new topologies. */
- topology = build_update_topology(sdp_update_cases[idx]->update_1);
- if (!topology) {
- ast_test_status_update(test, "Failed to build first update SDP state topology\n");
- goto end;
- }
- status = ast_sdp_state_update_local_topology(test_state, topology);
- ast_stream_topology_free(topology);
- if (status) {
- ast_test_status_update(test, "Failed to update first update SDP state topology\n");
- goto end;
- }
- if (sdp_update_cases[idx]->update_2) {
- topology = build_update_topology(sdp_update_cases[idx]->update_2);
- if (!topology) {
- ast_test_status_update(test, "Failed to build second update SDP state topology\n");
- goto end;
- }
- status = ast_sdp_state_update_local_topology(test_state, topology);
- ast_stream_topology_free(topology);
- if (status) {
- ast_test_status_update(test, "Failed to update second update SDP state topology\n");
- goto end;
- }
- }
-
- /* Get the SDP offer to merge the updates into the initial topology. */
- if (!ast_sdp_state_get_local_sdp(test_state)) {
- ast_test_status_update(test, "Failed to create offer SDP\n");
- goto end;
- }
-
- /* Check that the offered topology matches the expected topology. */
- topology = build_update_topology(sdp_update_cases[idx]->expected);
- if (!topology) {
- ast_test_status_update(test, "Failed to build expected topology\n");
- goto end;
- }
- status = cmp_update_topology(test, topology,
- ast_sdp_state_get_local_topology(test_state));
- ast_stream_topology_free(topology);
- if (status) {
- ast_test_status_update(test, "Failed to match expected topology\n");
- goto end;
- }
-
- /* Repeat for each test case defined. */
- ast_sdp_state_free(test_state);
- test_state = NULL;
- }
- res = AST_TEST_PASS;
-
-end:
- ast_sdp_state_free(test_state);
- return res;
-}
-
-static int unload_module(void)
-{
- AST_TEST_UNREGISTER(invalid_rtpmap);
- AST_TEST_UNREGISTER(rtpmap);
- AST_TEST_UNREGISTER(find_attr);
- AST_TEST_UNREGISTER(topology_to_sdp);
- AST_TEST_UNREGISTER(sdp_to_topology);
- AST_TEST_UNREGISTER(sdp_negotiation_initial);
- AST_TEST_UNREGISTER(sdp_negotiation_type_change);
- AST_TEST_UNREGISTER(sdp_negotiation_decline_incompatible);
- AST_TEST_UNREGISTER(sdp_negotiation_decline_max_streams);
- AST_TEST_UNREGISTER(sdp_negotiation_not_acceptable);
- AST_TEST_UNREGISTER(sdp_ssrc_attributes);
- AST_TEST_UNREGISTER(sdp_update_topology);
-
- return 0;
-}
-
-static int load_module(void)
-{
- AST_TEST_REGISTER(invalid_rtpmap);
- AST_TEST_REGISTER(rtpmap);
- AST_TEST_REGISTER(find_attr);
- AST_TEST_REGISTER(topology_to_sdp);
- AST_TEST_REGISTER(sdp_to_topology);
- AST_TEST_REGISTER(sdp_negotiation_initial);
- AST_TEST_REGISTER(sdp_negotiation_type_change);
- AST_TEST_REGISTER(sdp_negotiation_decline_incompatible);
- AST_TEST_REGISTER(sdp_negotiation_decline_max_streams);
- AST_TEST_REGISTER(sdp_negotiation_not_acceptable);
- AST_TEST_REGISTER(sdp_ssrc_attributes);
- AST_TEST_REGISTER(sdp_update_topology);
-
- return AST_MODULE_LOAD_SUCCESS;
-}
-
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SDP tests");
diff --git a/tests/test_stream.c b/tests/test_stream.c
index 8c887048c..50f0ccbfd 100644
--- a/tests/test_stream.c
+++ b/tests/test_stream.c
@@ -38,6 +38,7 @@
#include "asterisk/format_cap.h"
#include "asterisk/format_cache.h"
#include "asterisk/channel.h"
+#include "asterisk/uuid.h"
AST_TEST_DEFINE(stream_create)
{
@@ -224,6 +225,70 @@ AST_TEST_DEFINE(stream_set_state)
return AST_TEST_PASS;
}
+AST_TEST_DEFINE(stream_metadata)
+{
+ RAII_VAR(struct ast_stream *, stream, NULL, ast_stream_free);
+ char track_label[AST_UUID_STR_LEN + 1];
+ const char *stream_track_label;
+ int rc;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "stream_metadata";
+ info->category = "/main/stream/";
+ info->summary = "stream metadata unit test";
+ info->description =
+ "Test that metadata operations on a stream works";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ stream = ast_stream_alloc("test", AST_MEDIA_TYPE_AUDIO);
+ if (!stream) {
+ ast_test_status_update(test, "Failed to create media stream given proper arguments\n");
+ return AST_TEST_FAIL;
+ }
+
+ stream_track_label = ast_stream_get_metadata(stream, "AST_STREAM_METADATA_TRACK_LABEL");
+ if (stream_track_label) {
+ ast_test_status_update(test, "New stream HAD a track label\n");
+ return AST_TEST_FAIL;
+ }
+
+ ast_uuid_generate_str(track_label, sizeof(track_label));
+ rc = ast_stream_set_metadata(stream, "AST_STREAM_METADATA_TRACK_LABEL", track_label);
+ if (rc != 0) {
+ ast_test_status_update(test, "Failed to add track label\n");
+ return AST_TEST_FAIL;
+ }
+
+ stream_track_label = ast_stream_get_metadata(stream, "AST_STREAM_METADATA_TRACK_LABEL");
+ if (!stream_track_label) {
+ ast_test_status_update(test, "Changed stream does not have a track label\n");
+ return AST_TEST_FAIL;
+ }
+
+ if (strcmp(stream_track_label, track_label) != 0) {
+ ast_test_status_update(test, "Changed stream did not return same track label\n");
+ return AST_TEST_FAIL;
+ }
+
+ rc = ast_stream_set_metadata(stream, "AST_STREAM_METADATA_TRACK_LABEL", NULL);
+ if (rc != 0) {
+ ast_test_status_update(test, "Failed to remove track label\n");
+ return AST_TEST_FAIL;
+ }
+
+ stream_track_label = ast_stream_get_metadata(stream, "AST_STREAM_METADATA_TRACK_LABEL");
+ if (stream_track_label) {
+ ast_test_status_update(test, "Changed stream still had a track label after we removed it\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
AST_TEST_DEFINE(stream_topology_create)
{
RAII_VAR(struct ast_stream_topology *, topology, NULL, ast_stream_topology_free);
@@ -254,6 +319,11 @@ AST_TEST_DEFINE(stream_topology_clone)
RAII_VAR(struct ast_stream_topology *, topology, NULL, ast_stream_topology_free);
RAII_VAR(struct ast_stream_topology *, cloned, NULL, ast_stream_topology_free);
struct ast_stream *audio_stream, *video_stream;
+ char audio_track_label[AST_UUID_STR_LEN + 1];
+ char video_track_label[AST_UUID_STR_LEN + 1];
+ const char *original_track_label;
+ const char *cloned_track_label;
+ int rc;
switch (cmd) {
case TEST_INIT:
@@ -279,6 +349,13 @@ AST_TEST_DEFINE(stream_topology_clone)
return AST_TEST_FAIL;
}
+ ast_uuid_generate_str(audio_track_label, sizeof(audio_track_label));
+ rc = ast_stream_set_metadata(audio_stream, "AST_STREAM_METADATA_TRACK_LABEL", audio_track_label);
+ if (rc != 0) {
+ ast_test_status_update(test, "Failed to add track label\n");
+ return AST_TEST_FAIL;
+ }
+
if (ast_stream_topology_append_stream(topology, audio_stream) == -1) {
ast_test_status_update(test, "Failed to append valid audio stream to stream topology\n");
ast_stream_free(audio_stream);
@@ -291,6 +368,13 @@ AST_TEST_DEFINE(stream_topology_clone)
return AST_TEST_FAIL;
}
+ ast_uuid_generate_str(video_track_label, sizeof(video_track_label));
+ rc = ast_stream_set_metadata(video_stream, "AST_STREAM_METADATA_TRACK_LABEL", video_track_label);
+ if (rc != 0) {
+ ast_test_status_update(test, "Failed to add track label\n");
+ return AST_TEST_FAIL;
+ }
+
if (ast_stream_topology_append_stream(topology, video_stream) == -1) {
ast_test_status_update(test, "Failed to append valid video stream to stream topology\n");
ast_stream_free(video_stream);
@@ -313,11 +397,45 @@ AST_TEST_DEFINE(stream_topology_clone)
return AST_TEST_FAIL;
}
+ original_track_label = ast_stream_get_metadata(ast_stream_topology_get_stream(topology, 0),
+ "AST_STREAM_METADATA_TRACK_LABEL");
+ if (!original_track_label) {
+ ast_test_status_update(test, "Original topology stream 0 does not contain metadata\n");
+ return AST_TEST_FAIL;
+ }
+ cloned_track_label = ast_stream_get_metadata(ast_stream_topology_get_stream(cloned, 0),
+ "AST_STREAM_METADATA_TRACK_LABEL");
+ if (!cloned_track_label) {
+ ast_test_status_update(test, "Cloned topology stream 0 does not contain metadata\n");
+ return AST_TEST_FAIL;
+ }
+ if (strcmp(original_track_label, cloned_track_label) != 0) {
+ ast_test_status_update(test, "Cloned topology stream 0 track label was not the same as the original\n");
+ return AST_TEST_FAIL;
+ }
+
if (ast_stream_get_type(ast_stream_topology_get_stream(cloned, 1)) != ast_stream_get_type(ast_stream_topology_get_stream(topology, 1))) {
ast_test_status_update(test, "Cloned video stream does not contain same type as original\n");
return AST_TEST_FAIL;
}
+ original_track_label = ast_stream_get_metadata(ast_stream_topology_get_stream(topology, 1),
+ "AST_STREAM_METADATA_TRACK_LABEL");
+ if (!original_track_label) {
+ ast_test_status_update(test, "Original topology stream 1 does not contain metadata\n");
+ return AST_TEST_FAIL;
+ }
+ cloned_track_label = ast_stream_get_metadata(ast_stream_topology_get_stream(cloned, 1),
+ "AST_STREAM_METADATA_TRACK_LABEL");
+ if (!cloned_track_label) {
+ ast_test_status_update(test, "Cloned topology stream 1 does not contain metadata\n");
+ return AST_TEST_FAIL;
+ }
+ if (strcmp(original_track_label, cloned_track_label) != 0) {
+ ast_test_status_update(test, "Cloned topology stream 1 track label was not the same as the original\n");
+ return AST_TEST_FAIL;
+ }
+
return AST_TEST_PASS;
}
@@ -2139,6 +2257,7 @@ static int unload_module(void)
AST_TEST_UNREGISTER(stream_set_type);
AST_TEST_UNREGISTER(stream_set_formats);
AST_TEST_UNREGISTER(stream_set_state);
+ AST_TEST_UNREGISTER(stream_metadata);
AST_TEST_UNREGISTER(stream_topology_create);
AST_TEST_UNREGISTER(stream_topology_clone);
AST_TEST_UNREGISTER(stream_topology_clone);
@@ -2169,6 +2288,7 @@ static int load_module(void)
AST_TEST_REGISTER(stream_set_type);
AST_TEST_REGISTER(stream_set_formats);
AST_TEST_REGISTER(stream_set_state);
+ AST_TEST_REGISTER(stream_metadata);
AST_TEST_REGISTER(stream_topology_create);
AST_TEST_REGISTER(stream_topology_clone);
AST_TEST_REGISTER(stream_topology_append_stream);
diff --git a/utils/Makefile b/utils/Makefile
index d62d45f4f..ae2af08e2 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -164,7 +164,7 @@ aelparse.c: $(ASTTOPDIR)/res/ael/ael_lex.c
$(CMD_PREFIX) mv "$@.new" "$@"
aelparse.o: _ASTCFLAGS+=-I$(ASTTOPDIR)/res -Wno-unused
-aelparse: LIBS+=-lm
+aelparse: LIBS+=-lm $(AST_CLANG_BLOCKS_LIBS)
aelparse: aelparse.o aelbison.o pbx_ael.o hashtab.o lock.o ael_main.o ast_expr2f.o ast_expr2.o strcompat.o pval.o extconf.o astmm.o
threadstorage.c: $(ASTTOPDIR)/main/threadstorage.c
@@ -174,6 +174,7 @@ threadstorage.c: $(ASTTOPDIR)/main/threadstorage.c
extconf.o: extconf.c
+conf2ael: LIBS+=$(AST_CLANG_BLOCKS_LIBS)
conf2ael: conf2ael.o ast_expr2f.o ast_expr2.o hashtab.o lock.o aelbison.o aelparse.o pbx_ael.o pval.o extconf.o strcompat.o astmm.o
check_expr2: $(ASTTOPDIR)/main/ast_expr2f.c $(ASTTOPDIR)/main/ast_expr2.c $(ASTTOPDIR)/main/ast_expr2.h astmm.o