从服务器获取 sdp 后尝试设置远程描述时出现"Session description is NULL"错误



我正在尝试编写一个android应用程序,显示我从d-id服务:https://docs.d-id.com/reference/get-started获得的流。这应该以图像和文本作为输入,并在输入文本的同时流回该图像移动库的视频。

它使用WebRTC流,我正试图实现它,但我被困在试图发送一个答案后,最初的报价。

这是我这样做的函数。对不起,我的代码墙,我正处于繁重的测试阶段:

我得到"Session描述为NULL"setRemoteDescription调用的onSetFailure(String s)回调错误

post("https://api.d-id.com/talks/streams", json, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("OKHTTP FAILURE: ", e.toString());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
String responseStr = response.body().string();
JsonObject jsonObject = JsonParser.parseString(responseStr).getAsJsonObject();
streamID = jsonObject.get("id").getAsString();
session_id = jsonObject.get("session_id").getAsString();
String stunUrl = jsonObject.get("iceServers").getAsJsonArray().get(0).getAsJsonObject().get("urls").getAsString();
String turnUrl = jsonObject.get("iceServers").getAsJsonArray().get(1).getAsJsonObject().get("urls").getAsJsonArray().get(0).getAsString();
String username = jsonObject.get("iceServers").getAsJsonArray().get(1).getAsJsonObject().get("username").getAsString();
String credential = jsonObject.get("iceServers").getAsJsonArray().get(1).getAsJsonObject().get("credential").getAsString();
String sdp = jsonObject.get("offer").getAsJsonObject().get("sdp").getAsString();
List<PeerConnection.IceServer> iceServers = new ArrayList<>();
iceServers.add(new PeerConnection.IceServer(stunUrl));
iceServers.add(new PeerConnection.IceServer(turnUrl, username, credential));
// Create peer connection
PeerConnectionFactory.initializeAndroidGlobals(activity, true, true, true);
PeerConnectionFactory factory = new PeerConnectionFactory(null);
PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
peerConnection = factory.createPeerConnection(rtcConfig, new MediaConstraints(), pcObserver);
SessionDescription sessionDesc = new SessionDescription(OFFER, sdp);
peerConnection.setRemoteDescription(new SimpleSdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
super.onCreateSuccess(sessionDescription);
peerConnection.createAnswer(new SimpleSdpObserver() {
@Override
public void onCreateSuccess(SessionDescription sessionDescription) {
peerConnection.setLocalDescription(new SimpleSdpObserver(), sessionDescription);
String json = "{"answer":{"type":"answer","sdp":""+sessionDescription.description+""},"session_id":""+session_id+""}";
post("https://api.d-id.com/talks/streams/"+streamID+"/sdp", json, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("ANSWER FAILURE: ", e.toString());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String responseStr = response.body().string();
Log.e("ANSWER SUCCESS: ", responseStr);
}
});
}
@Override
public void onCreateFailure(String s) {
super.onCreateFailure(s);
}
@Override
public void onSetSuccess() {
super.onSetSuccess();
}
@Override
public void onSetFailure(String s) {
super.onSetFailure(s);
}
}, new MediaConstraints());
}
@Override
public void onCreateFailure(String s) {
super.onCreateFailure(s);
}
@Override
public void onSetSuccess() {
super.onSetSuccess();
}
@Override
public void onSetFailure(String s) {
super.onSetFailure(s);
}
}, sessionDesc);
Log.e("OKHTTP SUCCESS: ", responseStr);
} else {
Log.e("OKHTTP UNSUCCESS: ", "");
}
}
});

这是我从服务器收到的sdp字符串。

v=0
o=- 1680708165776536 1 IN IP4 35.164.244.161
s=Mountpoint 7117298691349140
t=0 0
a=group:BUNDLE a v d
a=ice-options:trickle
a=fingerprint:sha-256 F8:F6:8D:3D:A4:B0:9C:7A:A4:4C:6C:11:5B:59:D4:7B:2C:02:55:87:31:84:87:C1:83:B4:5E:A2:F7:4C:A5:1A
a=extmap-allow-mixed
a=msid-semantic: WMS *
m=audio 9 UDP/TLS/RTP/SAVPF 111
c=IN IP4 35.164.244.161
a=sendonly
a=mid:a
a=rtcp-mux
a=ice-ufrag:ol8o
a=ice-pwd:QwtILzHdCR7CEZO8T5BpmV
a=ice-options:trickle
a=setup:actpass
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
a=msid:janus janusa
a=ssrc:575475372 cname:janus
a=candidate:1 1 udp 2015363327 35.164.244.161 41669 typ host
a=candidate:2 1 udp 1679819007 35.164.244.161 41669 typ srflx raddr 172.18.0.4 rport 41669
a=end-of-candidates
m=video 9 UDP/TLS/RTP/SAVPF 100 101
c=IN IP4 35.164.244.161
a=sendonly
a=mid:v
a=rtcp-mux
a=ice-ufrag:ol8o
a=ice-pwd:QwtILzHdCR7CEZO8T5BpmV
a=ice-options:trickle
a=setup:actpass
a=rtpmap:100 VP8/90000
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=ssrc-group:FID 1591203620 1663244846
a=msid:janus janusv
a=ssrc:1591203620 cname:janus
a=ssrc:1663244846 cname:janus
a=candidate:1 1 udp 2015363327 35.164.244.161 41669 typ host
a=candidate:2 1 udp 1679819007 35.164.244.161 41669 typ srflx raddr 172.18.0.4 rport 41669
a=end-of-candidates
m=application 9 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 35.164.244.161
a=sendrecv
a=mid:d
a=sctp-port:5000
a=ice-ufrag:ol8o
a=ice-pwd:QwtILzHdCR7CEZO8T5BpmV
a=ice-options:trickle
a=setup:actpass
a=candidate:1 1 udp 2015363327 35.164.244.161 41669 typ host
a=candidate:2 1 udp 1679819007 35.164.244.161 41669 typ srflx raddr 172.18.0.4 rport 41669
a=end-of-candidates

希望你能帮我理解这个问题。欢呼,塞缪尔。我尝试将会话描述创建为字符串化的JSON,改变了我做所有这些事情的顺序,以及许多其他徒劳的尝试。我还尝试使用sdpoker工具检查sdp问题,但我不理解输出。

在这里:

Found 11 error(s) in SDP file:
1: Stream 1: Each stream description shall have a media-level 'mediaclk' attribute, as per SMPTE ST 2110-10 Section 8.1.
2: Stream 2: Each stream description shall have a media-level 'mediaclk' attribute, as per SMPTE ST 2110-10 Section 8.1.
3: Stream 3: Each stream description shall have a media-level 'mediaclk' attribute, as per SMPTE ST 2110-10 Section 8.1.
4: Stream 1: Stream descriptions shall have a media-level 'ts-refclk' attribute, as per SMPTE ST 2110-10 Section 8.2.
5: Stream 2: Stream descriptions shall have a media-level 'ts-refclk' attribute, as per SMPTE ST 2110-10 Section 8.2.
6: Stream 3: Stream descriptions shall have a media-level 'ts-refclk' attribute, as per SMPTE ST 2110-10 Section 8.2.
7: Line 46: Separate source address grouping is not an acceptable pattern, with reference to RFC 7104.
8: Line 5: Separate destination address grouping is not an acceptable pattern, with reference to RFC 7104.
9: Got to line 10, the end of session-level description, without finding the destination group, with reference to RFC 7104.
10: Line 27: Found a media description for video with a pattern that is not acceptable.
11: Line 10: Found a media description for audio with a pattern that is not acceptable.

尝试先设置本地描述,再设置远程描述。