<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
  <!ENTITY % ents SYSTEM 'xep.ent'>
%ents;
]>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep>
<header>
  <title>Jingle Early Media</title>
  <abstract>This specification describes methods for exchanging early media in the context of Jingle RTP sessions.</abstract>
  &LEGALNOTICE;
  <number>0269</number>
  <status>Deferred</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0166</spec>
    <spec>XEP-0167</spec>
    <spec>RFC 3550</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>N/A</shortname>
  <discuss>jingle</discuss>
  &diana;
  &stpeter;
  <revision>
    <version>0.1</version>
    <date>2009-05-19</date>
    <initials>dc/psa</initials>
    <remark><p>Initial version, copied from XEP-0167.</p></remark>
  </revision>
</header>

<section1 topic='Introduction' anchor='intro'>
  <p>&xep0166; can be used to initiate and negotiate a wide range of peer-to-peer sessions, including &xep0167; (mainly for voice and video) using the Realtime Transport Protocol (RTP; see &rfc3550;). This document describes call flows for so-called "early media" using Jingle.</p>
</section1>

<section1 topic='Concepts' anchor='concepts'>
  <p>The term "early media" refers to media that is exchanged before a responder has definitively accepted a session request generated by an initiator or before end-to-end connectivity has been established (e.g., the media could be generated by an intermediate call manager or media relay). Early media is typically used to send ringing tones and announcements, using either audio streams or Dual Tone Multi-Frequency (DTMF) events.</p>
  <p>In Jingle, the exchange of early media is established through use of the "content-add" action. In order to match the usage specified in &rfc3959; and &rfc3960;, when adding a content definition for early media the value of the &CONTENT; element's 'disposition' attribute MUST be "early-session" for mapping to a SIP Content-Disposition header value of "early-session". This enables endpoints or intermediate gateways to apply the application server model described in <cite>RFC 3960</cite>.</p>
  <p>An entity that generates a content-add message for early media SHOULD specify the same codecs for both session media and early media (however, it is possible that the entity that generates the early media does not generate the session media, for example in the case of an intermediate gateway or application server; in this case the entity MUST use one of the codecs advertised by the initiator).</p>
  <p>Upon receiving a content-add message specifying the use of early media, the initiator's client SHOULD acknowledge the content-add, complete any required transport negotiation, and then send a content-accept (or content-reject) to the sender. When the responder subsequently sends a session-accept message, the acceptance MUST NOT be construed to include the content definition whose disposition is "early-session".</p>
  <p>In handling early media and deciding whether to generate local ringing or to play early media received from the responder or an intermediate gateway, the initiator's client SHOULD proceed as follows:</p>
  <ol>
    <li>If no ringing notification is received via a session-info event containing a &lt;ringing/&gt; condition, do not generate local ringing.</li>
    <li>If a ringing notification is received and no early media is received, generate local ringing.</li>
    <li>If a ringing notification is received but early media is received, play the early media and do not generate local media.</li>
    <li>Once the responder has accepted the session and the session data (as opposed to early session data) has begun to flow, stop local ringing or stop playing early media.</li>
  </ol>
  <p>For examples of early media, see the <link url='#scenarios-earlymedia'>Jingle Audio via RTP with Early Media</link> section of this document.</p>
</section1>

<section1 topic='Scenario' anchor='scenario'>
  <p>In this scenario, Romeo initiates a voice chat with Juliet using a transport method of ICE-UDP. There is a gateway between Romeo and Juliet, and the gateway functions as an application server by returning early media to Romeo (perhaps some late medieval hold music or an old-fashioned IVR interaction). To simplify the flow, we have left out any ringing notifications generated by Juliet.</p>
  <p>The session flow is as follows.</p> 
  <code><![CDATA[
Romeo                    Gateway                    Juliet
  |                         |                         |
  |   session-initiate      |                         |
  |   (audio definition)    |                         |
  |------------------------>|   session-initiate      |
  |   ack                   |------------------------>|
  |<------------------------|                         |
  |   content-add           |   ack                   |
  |   (early media)         x<------------------------|
  |<------------------------|                         |
  |   ack                   |                         |
  |------------------------>|                         |
  |   [TRANSPORT SETUP]     |                         |
  |<----------------------->|                         |
  |   content-accept        |                         |
  |------------------------>|                         |
  |   ack                   |                         |
  |<------------------------|                         |
  |   EARLY MEDIA (RTP)     |                         |
  |<=======================>|                         |
  |                         |   session-accept        |
  |                         |<------------------------|
  |   session-accept        |                         |
  |<------------------------|                         |
  |   ack                   |                         |
  |------------------------>|   ack                   |
  |                         |------------------------>|
  |                    AUDIO (RTP)                    |
  |<=================================================>|
  |                         |   session-terminate     |
  |                         |<------------------------|
  |   session-terminate     |                         |
  |<------------------------|                         |
  |   ack                   |                         |
  |------------------------>|   ack                   |
  |                         |------------------------>|
  |                         |                         |
  ]]></code>
  <p>The protocol flow is as follows, showing only the stanzas sent between Romeo and the gateway (acting on Juliet's behalf).</p>
  <example caption="Initiator sends session-initiate"><![CDATA[
<iq from='romeo@montague.lit/orchard'
    id='ox73bf9h'
    to='juliet@capulet.lit/balcony'
    type='set'>
  <jingle xmlns='urn:xmpp:jingle:1'
          action='session-initiate'
          initiator='romeo@montague.lit/orchard'
          sid='a73sjjvkla37jfea'>
    <content creator='initiator' name='voice'>
      <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
        <payload-type id='96' name='speex' clockrate='16000'/>
        <payload-type id='97' name='speex' clockrate='8000'/>
        <payload-type id='18' name='G729'/>
        <payload-type id='103' name='L16' clockrate='16000' channels='2'/>
        <payload-type id='98' name='x-ISAC' clockrate='8000'/>
      </description>
      <transport xmlns='urn:xmpp:jingle:transports:ice-udp:1'
                 pwd='asd88fgpdd777uzjYhagZg'
                 ufrag='8hhy'>
        <candidate component='1'
                   foundation='1'
                   generation='0'
                   id='el0747fg11'
                   ip='10.0.1.1'
                   network='1'
                   port='8998'
                   priority='2130706431'
                   protocol='udp'
                   type='host'/>
        <candidate component='1'
                   foundation='2'
                   generation='0'
                   id='y3s2b30v3r'
                   ip='192.0.2.3'
                   network='1'
                   port='45664'
                   priority='1694498815'
                   protocol='udp'
                   rel-addr='10.0.1.1'
                   rel-port='8998'
                   type='srflx'/>
      </transport>
    </content>
  </jingle>
</iq>
  ]]></example>
  <example caption="Responder acknowledges session-initiate"><![CDATA[
<iq from='juliet@capulet.lit/balcony'
    id='ox73bf9h'
    to='romeo@montague.lit/orchard'
    type='result'/>
  ]]></example>
  <p>Now the gateway sends a content-add message to Romeo while waiting for Juliet to pay attention to her telephony interface. It specifies a transport method of Raw UDP because it hosts its own media relay.</p>
  <example caption="Gateway sends content-add on behalf of responder"><![CDATA[
<iq from='juliet@capulet.lit/balcony'
    id='s12f7hb5'
    to='romeo@montague.lit/orchard'
    type='set'>
  <jingle xmlns='urn:xmpp:jingle:1'
          action='content-add'
          initiator='romeo@montague.lit/orchard'
          sid='a73sjjvkla37jfea'>
    <content creator='responder' 
             disposition='early-session'
             name='hold music'
             senders='responder'>
      <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
        <payload-type id='18' name='G729'/>
      </description>
      <transport xmlns='urn:xmpp:jingle:transports:raw-udp:1'
                 pwd='YH75Fviy6338Vbrhrlp8Yh'
                 ufrag='9uB6'>
        <candidate component='1'
                   generation='0'
                   id='a9j3mnbtu1'
                   ip='10.1.1.104'
                   port='13540'/>
      </transport>
    </content>
  </jingle>
</iq>
  ]]></example>
  <p>Romeo then acknowledges the content-add action.</p>
  <example caption="Initiator acknowledges content-add"><![CDATA[
<iq from='romeo@montague.lit/orchard'
    id='s12f7hb5'
    to='juliet@capulet.lit/balcony'
    type='result'/>
  ]]></example>
  <p>Because the gateway (on behalf of the responder) specified a transport method of Raw UDP for the early session data, in accordance with the <cite>Jingle Raw UDP Transport Method</cite> the initiator then SHOULD also send a Raw UDP candidate to the gateway in a transport-info message.</p>
  <example caption="Initiator sends transport-info"><![CDATA[
<iq from='romeo@montague.lit/orchard'
    id='xk2d1a85'
    to='juliet@capulet.lit/balcony'
    type='set'>
  <jingle xmlns='urn:xmpp:jingle:1'
          action='transport-info'
          initiator='romeo@montague.lit/orchard'
          responder='juliet@capulet.lit/balcony'
          sid='a73sjjvkla37jfea'>
    <content creator='initiator' name='voice'>
      <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
        <payload-type id='18' name='G729'/>
      </description>
      <transport xmlns='urn:xmpp:jingle:transports:raw-udp:1'>
        <candidate component='1'
                   generation='0'
                   id='z7sdjb01hf'
                   ip='208.68.163.214'
                   port='9876'/>
        <candidate component='2'
                   generation='0'
                   id='hg92lsn10b'
                   ip='208.68.163.214'
                   port='9877'/>
      </transport>
    </content>
  </jingle>
</iq>
  ]]></example>
  <p>The gateway would acknowledge receipt of the candidate (not shown here) and both parties would attempt to establish connectivity for early media using the communicated transports.</p>
  <p>Eventually the initiator would send a content-accept to the gateway.</p>
  <example caption="Initiator accepts new content definition"><![CDATA[
<iq from='romeo@montague.lit/orchard'
    id='l8h4bg8q'
    to='juliet@capulet.lit/balcony'
    type='set'>
  <jingle xmlns='urn:xmpp:jingle:1'
          action='content-accept'
          initiator='romeo@montague.lit/orchard'
          sid='a73sjjvkla37jfea'>
    <content creator='responder' 
             disposition='early-session'
             name='hold music'
             senders='responder'>
      <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
        <payload-type id='18' name='G729'/>
      </description>
      <transport xmlns='urn:xmpp:jingle:transports:raw-udp:1'/>
    </content>
  </jingle>
</iq>
  ]]></example>
  <p>The gateway then acknowledges the acceptance on behalf of Juliet.</p>
  <example caption="Gateway acknowledges content-accept"><![CDATA[
<iq from='juliet@capulet.lit/balcony'
    id='l8h4bg8q'
    to='romeo@montague.lit/orchard'
    type='result'/>
  ]]></example>
  <p>Because Romeo has attempted to send test media to the gateway as described in <cite>XEP-0177</cite>, he has exposed an IP/port to which the gateway can now send early media via the media relay that it hosts.</p>
  <p>Eventually, the responder sends a session-accept.</p>
  <example caption="Responder sends session-accept"><![CDATA[
<iq from='juliet@capulet.lit/balcony'
    id='vh3bf781'
    to='romeo@montague.lit/orchard'
    type='set'>
  <jingle xmlns='urn:xmpp:jingle:1'
          action='session-accept'
          initiator='romeo@montague.lit/orchard'
          responder='juliet@capulet.lit/balcony'
          sid='a73sjjvkla37jfea'>
    <content creator='initiator' name='voice'>
      <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
        <payload-type id='97' name='speex' clockrate='8000'/>
        <payload-type id='18' name='G729'/>
      </description>
      <transport xmlns='urn:xmpp:jingle:transports:ice-udp:1'>
        <candidate component='1'
                   foundation='1'
                   generation='0'
                   id='or2ii2syr1'
                   ip='192.0.2.1'
                   network='0'
                   port='3478'
                   priority='2130706431'
                   protocol='udp'
                   type='host'/>
      </transport>
    </content>
  </jingle>
</iq>
  ]]></example>
  <example caption="Initiator acknowledges session-accept"><![CDATA[
<iq from='romeo@montague.lit/orchard'
    id='vh3bf781'
    to='juliet@capulet.lit/balcony'
    type='result'/>
  ]]></example>
  <p>Once end-to-end connectivity is established (which might necessitate the exchange of additional candidates via transport-info messages), the parties begin to exchange media; as a result, Romeo and the gateway terminate the exchange of early media (this does not necessitate exchange of a content-remove message, since the endpoint and the gateway can simply stop sending media).</p>
  <p>The endpoints can continue the session as long as desired.</p>
  <p>Eventually, one of the endpoints terminates the session.</p>
  <example caption="Responder terminates the session"><![CDATA[
<iq from='juliet@capulet.lit/balcony'
    id='gi49vx54'
    to='romeo@montague.lit/orchard'
    type='set'>
  <jingle xmlns='urn:xmpp:jingle:1'
          action='session-terminate'
          initiator='romeo@montague.lit/orchard'
          sid='a73sjjvkla37jfea'>
    <reason>
      <success/>
      <text>Sorry, gotta go!</text>
    </reason>
  </jingle>
</iq>
  ]]></example>
  <p>The other party then acknowledges termination of the session.</p>
  <example caption="Initiator acknowledges termination"><![CDATA[
<iq from='romeo@montague.lit/orchard'
    id='gi49vx54'
    to='juliet@capulet.lit/balcony'
    type='result'/>
  ]]></example>
</section1>

<section1 topic='Security Considerations' anchor='security'>
  <p>For security considerations, refer to <cite>XEP-0167</cite>.</p>
</section1>

<section1 topic='IANA Considerations' anchor='iana'>
  <p>This document requires no interaction with &IANA;.</p>
</section1>

<section1 topic='XMPP Registrar Considerations' anchor='registrar'>
  <p>This document requires no interaction with the &REGISTRAR;.</p>
</section1>

</xep>
