asterisk/res/ari
Matthew Jordan a528dfc9a7 ARI/PJSIP: Apply requesting channel's format cap to created channels
This patch addresses the following problems:
* ari/resource_channels: In ARI, we currently create a format capability
  structure of SLIN and apply it to the new channel being created. This was
  originally done when the PBX core was used to create the channel, as there
  was a condition where a newly created channel could be created without any
  formats. Unfortunately, now that the Dial API is being used, this has two
  drawbacks:
  (a) SLIN, while it will ensure audio will flows, can cause a lot of
      needless transcodings to occur, particularly when a Local channel is
      created to the dialplan. When no format capabilities are available, the
      Dial API handles this better by handing all audio formats to the requsted
      channels. As such, we defer to that API to provide the format
      capabilities.
  (b) If a channel (requester) is causing this channel to be created, we
      currently don't use its format capabilities as we are passing in our own.
      However, the Dial API will use the requester channel's formats if none
      are passed into it, and the requester channel exists and has format
      capabilities. This is the "best" scenario, as it is the most likely to
      create a media path that minimizes transcoding.
  Fixing this simply entails removing the providing of the format capabilities
  structure to the Dial API.

* chan_pjsip: Rather than blindly picking the first format in the format
  capability structure - which actually *can* be a video or text format - we
  select an audio format, and only pick the first format if that fails. That
  minimizes the weird scenario where we attempt to transcode between video/audio.

* res_pjsip_sdp_rtp: Applied the joint capapbilites to the format structure.
  Since ast_request already limits us down to one format capability once the
  format capabilities are passed along, there's no reason to squelch it here.

* channel: Fixed a comment. The reason we have to minimize our requested
  format capabilities down to a single format is due to Asterisk's inability
  to convey the format to be used back "up" a channel chain. Consider the
  following:

    PJSIP/A => L;1 <=> L;2 => PJSIP/B
    g,u,a     g,u,a    g,u,a      u

  That is, we have PJSIP/A dialing a Local channel, where the Local;2 dials
  PJSIP/B. PJSIP/A has native format capabilities g722,ulaw,alaw; the Local
  channel has inherited those format capabilities down the line; PJSIP/B
  supports only ulaw. According to these format capabilities, ulaw is
  acceptable and should be selected across all the channels, and no
  transcoding should occur. However, there is no way to convey this: when L;2
  and PJSIP/B are put into a bridge, we will select ulaw, but that is not
  conveyed to PJSIP/A and L;1. Thus, we end up with:

    PJSIP/A <=> L;1 <=> L;2 <=> PJSIP/B
      g          g   X   u        u

  Which causes g722 to be written to PJSIP/B.

  Even if we can convey the 'ulaw' choice back up the chain (which through
  some severe hacking in Local channels was accomplished), such that the chain
  looks like:

    PJSIP/A <=> L;1 <=> L;2 <=> PJSIP/B
      u          u       u         u

  We have no way to tell PJSIP/A's *channel driver* to Answer in the SDP back
  with only 'ulaw'. This results in all the channel structures being set up
  correctly, but PJSIP/A *still* sending g722 and causing the chain to fall
  apart.

  There's a lot of difficulty just in setting this up, as there are numerous
  race conditions in the act of bridging, and no clean mechanism to pass the
  selected format backwards down an established channel chain. As such, the
  best that can be done at this point in time is clarifying the comment.

Review: https://reviewboard.asterisk.org/r/4434/

ASTERISK-24812 #close
Reported by: Matt Jordan
........

Merged revisions 432195 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@432196 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-02-24 22:00:51 +00:00
..
ari_model_validators.c ARI/AMI: Include language in standard channel snapshot output 2014-12-09 20:20:27 +00:00
ari_model_validators.h ARI/AMI: Include language in standard channel snapshot output 2014-12-09 20:20:27 +00:00
ari_websockets.c ari_websockets: removed extra check on websocket session read 2015-02-11 17:45:00 +00:00
cli.c Rename everything Stasis-HTTP to ARI 2013-07-27 23:11:02 +00:00
config.c res_http_websocket: Close websocket correctly and use careful fwrite 2014-06-26 12:21:14 +00:00
internal.h res_http_websocket: Close websocket correctly and use careful fwrite 2014-06-26 12:21:14 +00:00
resource_applications.c res_ari: Fix various memory leaks. 2014-01-12 22:24:27 +00:00
resource_applications.h ARI: Fix endpoint/channel subscription issues; allow for subscriptions to tech 2014-07-22 16:20:58 +00:00
resource_asterisk.c ari: User better nicknames for ARI operations 2013-11-07 21:10:31 +00:00
resource_asterisk.h ARI: Remove unnecessary \briefs from automatically generated documentation 2014-07-02 21:13:46 +00:00
resource_bridges.c ARI: Improve wiki documentation 2015-01-27 17:21:03 +00:00
resource_bridges.h ARI: Improve wiki documentation 2015-01-27 17:21:03 +00:00
resource_channels.c ARI/PJSIP: Apply requesting channel's format cap to created channels 2015-02-24 22:00:51 +00:00
resource_channels.h ARI/PJSIP: Add the ability to redirect (transfer) a channel in a Stasis app 2015-02-12 20:34:37 +00:00
resource_device_states.c res_ari: Fix various memory leaks. 2014-01-12 22:24:27 +00:00
resource_device_states.h ARI: Remove unnecessary \briefs from automatically generated documentation 2014-07-02 21:13:46 +00:00
resource_endpoints.c Multiple revisions 420089-420090,420097 2014-08-05 21:44:09 +00:00
resource_endpoints.h Multiple revisions 420089-420090,420097 2014-08-05 21:44:09 +00:00
resource_events.c ARI: Add ability to raise arbitrary User Events 2014-05-22 16:09:51 +00:00
resource_events.h ARI: Improvements to body parameters documentation 2014-07-03 16:14:39 +00:00
resource_mailboxes.c ARI: Add mailboxes resource for controlling and polling external MWI 2014-01-14 23:44:57 +00:00
resource_mailboxes.h ARI: Remove unnecessary \briefs from automatically generated documentation 2014-07-02 21:13:46 +00:00
resource_playbacks.c res_ari: Fix various memory leaks. 2014-01-12 22:24:27 +00:00
resource_playbacks.h ARI: Remove unnecessary \briefs from automatically generated documentation 2014-07-02 21:13:46 +00:00
resource_recordings.c ari: Add a copy operation for stored recordings 2014-07-18 21:48:46 +00:00
resource_recordings.h ari: Add a copy operation for stored recordings 2014-07-18 21:48:46 +00:00
resource_sounds.c media formats: re-architect handling of media for performance improvements 2014-07-20 22:06:33 +00:00
resource_sounds.h ARI: Remove unnecessary \briefs from automatically generated documentation 2014-07-02 21:13:46 +00:00