user12384512
user12384512

Reputation: 3401

SIP codec negotiation

[Offer]

      v=0
      o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com
      s=
      c=IN IP4 host.atlanta.example.com
      t=0 0
      m=audio 49170 RTP/AVP 0 8 97
      a=rtpmap:0 PCMU/8000
      a=rtpmap:8 PCMA/8000
      a=rtpmap:97 iLBC/8000
      m=video 51372 RTP/AVP 31 32
      a=rtpmap:31 H261/90000
      a=rtpmap:32 MPV/90000


[Answer]

  v=0
  o=bob 2808844564 2808844564 IN IP4 host.biloxi.example.com
  s=
  c=IN IP4 host.biloxi.example.com
  t=0 0
  m=audio 49172 RTP/AVP 0 8
  a=rtpmap:0 PCMU/8000
  a=rtpmap:8 PCMA/8000
  m=video 0 RTP/AVP 31
  a=rtpmap:31 H261/90000

I'm sending INVITE with 3 audio supported codecs, as result I receive 2 codecs which match my setup. PCMU and PCMA.

Which codec should I use eventually to avoid transcoding on the other side? I believe I can determine codec of incoming stream simply looking into the payload of RTP packet. However it's not clear which codec should I use to encode outgoing stream ? First from the list ? Any from the list ? Or same codec which was used for incoming stream

Is it ok if I encode outgoing stream with PCMA and decode incoming with PCMU ?

Upvotes: 3

Views: 7155

Answers (3)

segfault
segfault

Reputation: 66

I disagree with Liviu and Rajesh.. You should be prepared to receive on BOTH (PCMU and PCMA) at any time. (They could alternate if the Far End wanted too). You have established and accepted BOTH codec.. I will presume you also ACK-ed both aswell.

If you want to have only a single Codec; you must re-invite with just the one you want to use. (See section 2.2 of RFC 4317) for the "second-Answer".

In the "real world" because both sides of the call are capable of using "Either" of the codec provided and agreed too, then picking the first is allowed. but you should be also allowing the second if the far end chooses to use it. And I dont think you provide for that. However; re-invite with only one codec, will ensure that only that one will ever be used.

Upvotes: 5

Rajesh
Rajesh

Reputation: 670

Seconding the previous users answers i just wanted to add something.

I haven't come across a line in SDP spec that specifies that the order of the codec is the priority / preference order. But in most implementation i have found that is the case.

So in this case usually 0 [PCMU] is what the end point shall start sending media with and what UAC should also pick. If UAC decided to do 8 [PCMA] because no packets arrived from the UAS, that could potentially lead to need to transcoding / rating service on either side of the call.

BTW, since the Answer was accepted for both the codec it does show the ability of the UAS to be handle either of the codec on the same port.

Some other options are checking first packet and deciding codec, starting with either of these and then switching to the same in subsequent Re-INVITE so that transcoding services can be removed from the call.

Upvotes: 2

Liviu Chircu
Liviu Chircu

Reputation: 1074

The SDP answer clearly establishes the following:

  • the codec used for the outgoing stream
  • the codec used for the incoming stream

You should be looking for the first codec in the "m=" line, since the "a=" lines may be mixed up. In our case, the decided codec is 0 (PCMU)

Upvotes: 2

Related Questions