Create Answer can't be called before setRemoteDescription

8,641 views
Skip to first unread message

Tobias Guennewig

unread,
Nov 18, 2012, 2:56:55 PM11/18/12
to discuss-webrtc
Hello,

I always get this error, when i want to create my SDP answer. Seems
like an easy to solve problem, but i always call setRemoteDescription
before i call createAnswer. Here is the relevant code:

var sd = {
sdp : sdp,
type : 'offer'
};
pc.setRemoteDescription(new RTCSessionDescription(
sd));
pc.createAnswer(function(sessionDescription) {
pc.setLocalDescription(sessionDescription);
// Send answer to peer
sendMessage(Method.SEND_ANSWER,sessionDescription.sdp);
}, function(error) {
console.log("Could not create SDP answer! Reason: " + error);
}, {
has_audio : true,
has_video : true
});

The variable sdp stores:

v=0
o=- 4267985828 9 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video
m=audio 56959 RTP/SAVPF 103 104 0 8 106 105 13 126
c=IN IP4 92.228.253.199
a=rtcp:56959 IN IP4 92.228.253.199
a=candidate:704553097 1 udp 2113937151 192.168.1.3 56958 typ host
generation 0
a=candidate:704553097 2 udp 2113937151 192.168.1.3 56958 typ host
generation 0
a=candidate:2158047068 1 udp 1677729535 92.228.253.199 56959 typ srflx
generation 0
a=candidate:2158047068 2 udp 1677729535 92.228.253.199 56959 typ srflx
generation 0
a=candidate:1736268921 1 tcp 1509957375 192.168.1.3 64113 typ host
generation 0
a=candidate:1736268921 2 tcp 1509957375 192.168.1.3 64113 typ host
generation 0
a=ice-ufrag:vOuOJrv+CqOjFy6c
a=ice-pwd:hThZ9i0Q1BGYJkP+Fs2hK17B
a=ice-options:google-ice
a=sendrecv
a=mid:audio
a=rtcp-mux
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:7ZCFcn0H8QVQu00vLtB0/
Lfr5DKkGIEOclzljhNG
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:106 CN/32000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:126 telephone-event/8000
a=ssrc:3645841120 cname:xaUL8Ns3GSC9NSYw
a=ssrc:3645841120 mslabel:5v1aOYq72fGJGWAjHIUkXsU5lKXUohBgiOH9
a=ssrc:3645841120 label:5v1aOYq72fGJGWAjHIUkXsU5lKXUohBgiOH900
m=video 56959 RTP/SAVPF 100 101 102
c=IN IP4 92.228.253.199
a=rtcp:56959 IN IP4 92.228.253.199
a=candidate:704553097 1 udp 2113937151 192.168.1.3 56958 typ host
generation 0
a=candidate:704553097 2 udp 2113937151 192.168.1.3 56958 typ host
generation 0
a=candidate:2158047068 1 udp 1677729535 92.228.253.199 56959 typ srflx
generation 0
a=candidate:2158047068 2 udp 1677729535 92.228.253.199 56959 typ srflx
generation 0
a=candidate:1736268921 1 tcp 1509957375 192.168.1.3 64113 typ host
generation 0
a=candidate:1736268921 2 tcp 1509957375 192.168.1.3 64113 typ host
generation 0
a=ice-ufrag:vOuOJrv+CqOjFy6c
a=ice-pwd:hThZ9i0Q1BGYJkP+Fs2hK17B
a=ice-options:google-ice
a=sendrecv
a=mid:video
a=rtcp-mux
a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:7ZCFcn0H8QVQu00vLtB0/
Lfr5DKkGIEOclzljhNG
a=rtpmap:100 VP8/90000
a=rtpmap:101 red/90000
a=rtpmap:102 ulpfec/90000
a=ssrc:2324717541 cname:xaUL8Ns3GSC9NSYw
a=ssrc:2324717541 mslabel:5v1aOYq72fGJGWAjHIUkXsU5lKXUohBgiOH9
a=ssrc:2324717541 label:5v1aOYq72fGJGWAjHIUkXsU5lKXUohBgiOH910

I dont know what to do.
Thanks for your help!

Bryan Donnovan

unread,
Nov 18, 2012, 4:00:04 PM11/18/12
to discuss...@googlegroups.com, tobias.g...@googlemail.com
the second parameter to setRemoteDescription is a completion callback.  Call createAnswer from within the callback to avoid a race condition:

pc.setRemoteDescription(new RTCSessionDescription( sessDesc, function(){
   pc.createAnswer(...)
});

Bryan Donnovan

unread,
Nov 18, 2012, 4:12:46 PM11/18/12
to discuss...@googlegroups.com, tobias.g...@googlemail.com
sorry, meant to write:

pc.setRemoteDescription( offer , function(){
    pc.createAnswer(...);
});

Tobias Guennewig

unread,
Nov 18, 2012, 4:25:39 PM11/18/12
to discuss-webrtc
Thank you very much! I added the two callback functions. Now i ve the
problem, that the failureCallback function gets invoked. The error
string just says: "setRemoteDescription failed".
The spec says: "The failureCallback will be called if the
RTCSessionDescription is a valid description but cannot be applied at
the media layer, e.g., if there are insufficient resources to apply
the SDP."
I dont know what this means. Any ideas how to solve the problem?

Hsu Ping Feng

unread,
Nov 18, 2012, 6:55:54 PM11/18/12
to discuss...@googlegroups.com
Try to pass new RTPSessionDescription(sdp)  as remote description, not with the sd object you created as the constructor parameter.


2012/11/19 Tobias Guennewig <tobias.g...@googlemail.com>

--






--
AUFKLÄRUNG ist der Ausgang des Menschen aus seiner selbstverschuldeten Unmündigkeit. Unmündigkeit ist das Unvermögen, sich seines Verstandes ohne Leitung eines anderen zu bedienen. Selbstverschuldet ist diese Unmündigkeit, wenn die Ursache derselben nicht am Mangel des Verstandes, sondern der Entschließung und des Mutes liegt, sich seiner ohne Leitung eines andern zu bedienen. Sapere aude! Habe Mut, dich deines eigenen Verstandes zu bedienen! ist also der Wahlspruch der Aufklärung.

Tobias Guennewig

unread,
Nov 21, 2012, 10:11:20 AM11/21/12
to discuss-webrtc
Hey, thanks for your reply. Unfortunately it does not work. I get an
error saying: "No object". the spec also states, that an object must
be provided as a parameter.
Damn, why i get this error?! :)

On 19 Nov., 00:55, Hsu Ping Feng <fillano.f...@gmail.com> wrote:
> Try to pass new RTPSessionDescription(sdp)  as remote description, not with
> the sd object you created as the constructor parameter.
>
> 2012/11/19 Tobias Guennewig <tobias.guenne...@googlemail.com>

Tobias Guennewig

unread,
Nov 21, 2012, 10:24:41 AM11/21/12
to discuss-webrtc
Maybe it is usefull, if i provide the code, which generates the
problem:

var sd = {
sdp : sdp,
type : 'offer'
};
pc.setRemoteDescription(new RTCSessionDescription(sd), function() {
pc.createAnswer(
function(sessionDescription) {
pc.setLocalDescription(sessionDescription);
// Send answer to peer
sendMessage(chalengo.Method.SEND_ANSWER, sessionDescription.sdp);
}, function(error) {
console.log("Could not create SDP answer! Reason: " + error);
}, {
has_audio : true,
has_video : true
});
}, function(e) {
console.log("Could not set remote description. Reason: " + e);
});

On 21 Nov., 16:11, Tobias Guennewig <tobias.guenne...@googlemail.com>
wrote:

hoangtuansu

unread,
Nov 22, 2012, 10:05:10 AM11/22/12
to discuss...@googlegroups.com, tobias.g...@googlemail.com
Hi,

In my sample code, the sdp (offer and answer) never include "a=candidate ..." which is the result of ICE process and happens separately with the offer/answer exchange. In my case, port number of m attribute is always 1. So i wonder how you can include such information to the sdp?

Tobias Guennewig

unread,
Nov 27, 2012, 11:24:34 AM11/27/12
to discuss-webrtc
Hey! Sorry for my late reply, i still want to solve this problem :)
This is how i create my offer:

function registerSession() {
pc.createOffer(function(sessionDescription) {
pc.setLocalDescription(sessionDescription,
function() {
// Success
}, function(e) {
// Failure
console.log("Could not set local description. Reason: "
+ e);
});}
,function(e) {
console.log("Could not create SDP offer! Reason: " + e);
}, {
'has_audio' : false,
'has_video' : false
});

if (moreIceCandidates) {
// First we must get all ICE candidates available, try again later
setTimeout(registerSession, 500);
return;
}
// Add media stream to the session
pc.addStream(chalengo.media.localStream);
// Create the offer for the session, which contains all ICE
candidates now!
pc.createOffer(function(sessionDescription) {
pc.setLocalDescription(sessionDescription,
function() {
// Success
console.log("set Desc");
}, function(e) {
// Failure
console.log("Could not set local description. Reason: "
+ e);
});
// Register session at the server
sendMessage(chalengo.Method.REGISTER_CONNECTION,
sessionDescription.sdp);
}, function(e) {
console.log("Could not create SDP offer! Reason: " + e);
}, {
'has_audio' : false,
'has_video' : false
});

moreIceCandidates is a variable, which is initially true and will be
set to false if onIceCandidate is invoked with a null candidate.
Unfortunately ICE candidate gathering is only startet after calling
setLocalDescription (see my second thread:
https://groups.google.com/group/discuss-webrtc/browse_thread/thread/5b8d765274a8a027/c0dd91ad6fd6a786#c0dd91ad6fd6a786).
Thats why i first create a dummy offer, to start ICE gathering. I set
has_audio and has_video to false, because i wanted to test, if its
working then.
Maybe i understand something wrong? I want to create an offer, which
already contains all candidates, so that i only have to send one
message to the server.

Thanks for your help!

Justin Uberti

unread,
Nov 29, 2012, 6:17:52 PM11/29/12
to discuss-webrtc
Sorry, I no longer understand the exact problem you're seeing. 

In any case, you don't need to call setLocalDescription the second time (after all candidates are gathered), just createOffer.


--




Piotr

unread,
Dec 3, 2012, 5:39:04 AM12/3/12
to discuss...@googlegroups.com
Hi,
I have the same problem. I also moved createAnswer to setRemoteDescription callback and also got the "SetRemoteDescription failed." error. I'm quite lost with how whole sequence should be designed... I refactored all my connection logic to handle situation when A is calling to B but B didn't allow media yet. In all examples I saw this situation either crashes application or is prevented before call as making calls is allowed after local stream is obtained (but this prevents multicalls as we can't reuse one local stream yet).

I came up with this solution:
1. A is calling to B, so he sends request over signalling channel and immediately creates peer connection, but not sending anything over it
2. B accepts call from A and
2.1. sends accept over signalling channel
2.2. creates his peer connection

then it gets async. When either A or B adds local stream to peer connection, setLocalDescription is called, offer is created and sent to peer. Receiver sets remote description, calls createAnswer and sets local description returned by it, then sends answer. And the problem is here. No answers are sent. You wrote that setLocalDescription should be called once. Can this cause the problem? What's more it works perfectly on localhost (between two browsers) and almost never on standalone server...

Thanks for any help!

Tobias Guennewig

unread,
Dec 4, 2012, 4:34:21 PM12/4/12
to discuss-webrtc
Hi finally could figure out the problem! setRemoteDescription always
fails if i call setLocalDescription with an sdp offer as an
argument.before.

The following sequence generates the error:

localOffer = createOffer()
setLocalDescription(localOffer)
sendOfferToServerWhereItMightBeFetchedByAPeer(localOffer)
*** Our offer was not fetched, but we could get an offer of a peer
***
peerOffer = receiveOfferFromPeer()
setRemoteDescription(peerOffer) <---- fails here
answer = createAnswer(peerOffer)
setLocalDescription(answer)

whereas this works:

localOffer = createOffer()
sendOfferToServerWhereItMightBeFetchedByAPeer(localOffer)
*** Our offer was not fetched, but we could get an offer of a peer
***
peerOffer = receiveOfferFromPeer()
setRemoteDescription(peerOffer) <---- fails here
answer = createAnswer(peerOffer)
setLocalDescription(answer)

The problem is, that i have to call setLocalDescription at the
beginning to start candidate gathering. Can i reset the state after i
called setLocalDescription as if i did not call it?

Thanks!

On 27 Nov., 17:24, Tobias Guennewig <tobias.guenne...@googlemail.com>
wrote:
> setLocalDescription (see my second thread:https://groups.google.com/group/discuss-webrtc/browse_thread/thread/5...).

Matthew Hessing

unread,
Nov 16, 2014, 7:20:54 PM11/16/14
to discuss...@googlegroups.com, tobias.g...@googlemail.com
Hey Tobias, did you solve this? I'm running into what appears to be an identical problem.

Harald Alvestrand

unread,
Nov 17, 2014, 5:41:18 AM11/17/14
to discuss...@googlegroups.com, tobias.g...@googlemail.com
Have you folks filled in the success and error callbacks of setRemoteDescription?

Remember that setRemoteDescription is not complete until the success callback is called (it's an async function), so you should really be calling createAnswer from the callback, not right after firing setRemoteDescription.

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Hessing

unread,
Nov 17, 2014, 10:53:21 AM11/17/14
to discuss...@googlegroups.com
My implementation is in iOS, so in our case the callbacks are handled via delegate methods (and these are implemented). The modification I made that appears to be working now follows like so:

- party A joins room
- party B joins room
- party A receives offer from party B
- party A sets Remote SDP to that sent by B
- party A gets callback, creates Answer
- party A sets Local SDP
- party A receives “addStream” event from B
- … party B video not showing on party A device ...

I’m now working on that last part. Feels like I’m pretty close to at least having 1-way video working.
You received this message because you are subscribed to a topic in the Google Groups "discuss-webrtc" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/discuss-webrtc/9zs21EBciNM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to discuss-webrt...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages