android 从服务器获取SDP后,尝试设置远程描述时,出现“会话描述为空”错误

fiei3ece  于 2023-04-10  发布在  Android
关注(0)|答案(1)|浏览(162)

我正在尝试编写一个Android应用程序,显示我从d-id服务获得的流:https://docs.d-id.com/reference/get-started。这应该采取一个图像和一个文本作为输入,并流回这个图像的视频移动库,同时说输入的文本。
它使用WebRTC进行流传输,我正在尝试实现它,但我在最初的报价后试图发送答案。
下面是我执行此操作的函数。很抱歉,代码墙,我正处于繁重的测试阶段:
我在setRemoteDescription调用的onSetFailure(String s)回调中得到“SessiondescriptionisNULL”错误

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.
rks48beu

rks48beu1#

在设置远程描述之前,请尝试先设置本地描述。

相关问题