Skip to content

Instantly share code, notes, and snippets.

@mtryfoss
Last active November 16, 2017 09:00
Show Gist options
  • Save mtryfoss/3f84daa607993367c029ce3976527303 to your computer and use it in GitHub Desktop.
Save mtryfoss/3f84daa607993367c029ce3976527303 to your computer and use it in GitHub Desktop.
Proof of concept for backwards negotiating of formats in Asterisk
--- channels/chan_sip.c (revision 6270)
+++ channels/chan_sip.c (working copy)
@@ -7227,6 +7227,18 @@
sip_pvt_unlock(p);
}
break;
+ case AST_FRAME_FORMAT:
+ if(!p->outgoing_call){
+ struct ast_format_cap *tmpcap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ ast_format_cap_append(tmpcap, frame->subclass.format, 0);
+ sip_pvt_lock(p);
+ ast_format_cap_replace_from_cap(p->jointcaps, tmpcap, AST_MEDIA_TYPE_UNKNOWN);
+ ast_format_cap_replace_from_cap(p->caps, tmpcap, AST_MEDIA_TYPE_UNKNOWN);
+ sip_pvt_unlock(p);
+ ao2_cleanup(tmpcap);
+ }
+ return 0;
+ break;
default:
ast_log(LOG_WARNING, "Can't send %u type frames with SIP write\n", frame->frametype);
return 0;
@@ -11179,6 +11191,13 @@
}
}
} else if (ast_format_cmp(format, ast_format_amrwb) == AST_FORMAT_CMP_EQUAL) {
+ if(p->outgoing_call && p->owner){
+ struct ast_frame f = { AST_FRAME_FORMAT };
+ f.subclass.format = format;
+ f.subclass.integer = 0;
+ ast_queue_frame(p->owner, &f);
+ }
+
// TODO FIXME - add parameter for this!
if (sscanf(fmtp_string, "octet-align=%30u", &octet_align) == 1) {
if(octet_align == 1) {
--- apps/app_dial.c (revision 6252)
+++ apps/app_dial.c (working copy)
@@ -1529,6 +1517,7 @@
}
/* Fall through */
case AST_FRAME_TEXT:
+ case AST_FRAME_FORMAT:
if (single && ast_write(in, f)) {
ast_log(LOG_WARNING, "Unable to write frametype: %u\n",
f->frametype);
@@ -1624,6 +1613,7 @@
goto skip_frame;
}
/* Fall through */
+ case AST_FRAME_FORMAT:
case AST_FRAME_TEXT:
case AST_FRAME_DTMF_BEGIN:
case AST_FRAME_DTMF_END:
--- include/asterisk/frame.h (revision 6245)
+++ include/asterisk/frame.h (working copy)
@@ -127,6 +127,7 @@
* directly into bridges.
*/
AST_FRAME_BRIDGE_ACTION_SYNC,
+ AST_FRAME_FORMAT,
};
#define AST_FRAME_DTMF AST_FRAME_DTMF_END
--- main/channel.c (revision 6245)
+++ main/channel.c (working copy)
@@ -1473,6 +1473,7 @@
case AST_FRAME_IAX:
case AST_FRAME_CNG:
case AST_FRAME_MODEM:
+ case AST_FRAME_FORMAT:
return 0;
}
return 0;
@@ -2819,6 +2820,7 @@
case AST_FRAME_BRIDGE_ACTION_SYNC:
case AST_FRAME_NULL:
case AST_FRAME_CNG:
+ case AST_FRAME_FORMAT:
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment