繁体   English   中英

为什么我在 Chrome 中工作时在 Android 中收到“无法为 m 节设置远程视频描述发送参数,mid='0'”错误?

[英]Why am I getting "Failed to set remote video description send parameters for m-section with mid='0'" error in Android when it works in Chrome?

背景资料

您好,我正在尝试在 Android 中构建一个 WebRTC 客户端,该客户端订阅使用 NodeJS 和 JavaScript 广播的视频源。

可以在Gabriel Tanner 的这篇可爱的文章中完整地查看广播公司代码。

在 Chrome 中的http://localhost:4000/broadcaster.html下的 localhost 中运行它,然后从网络上的另一台设备访问我的 IP 地址时,它运行良好。 我可以看到视频,而且几乎是实时的。

我已经尝试使用两种不同的网络摄像头设备(内置网络摄像头和 USB 网络摄像头)进行此操作,但即使 JavaScript 广播器和客户端工作正常,Android 客户端也无法工作。

手头的任务

在遵循教程并让示例运行后,我决定尝试实现我自己的 Android 应用程序,可以在我的 GitHub 上查看其整个源代码。

我在这个地方学习了各种教程,问题总是源于尝试设置远程描述,这是使用以下代码完成的:

    private void setRemoteDescription(Object[] arguments) {
        JSONObject message = (JSONObject) arguments[1];
        try {
            String sdp = message.getString("sdp");
            SessionDescription sessionDescription = new SessionDescription(OFFER, sdp);
            peerConnection.setRemoteDescription(new SimpleSdpObserver(), sessionDescription);
        } catch (JSONException e) {
            Log.e(TAG, "setRemoteDescription: failed to parse JSON", e);
        }
    }

就像我说的,可以在 GitHub 中查看完整的代码,我不想把这篇文章弄得乱七八糟,但基本上按照 Gabriel 的教程,当套接字在连接时发出“观察者”(Android 应用程序正确执行)时,它会然后发回一个“报价”,然后在客户端监听它,如下所示:

    private void bindSocketEvents() {
        socket.on(EVENT_CONNECT, args -> {
            socket.emit("watcher");
        }).on("broadcaster", args -> {
            socket.emit("watcher");
        }).on("offer", args -> {
            setRemoteDescription(args);
            performAnswer();
        }).on("candidate", this::addIceCandidate);
    }

然后我们看到,在“提供”时,我们使用 JavaScript 中的 args 调用代码并尝试设置远程描述,但它没有这样做。

这是我通过触发此获得的示例 SDP:

v=0
o=- 7040957491050894781 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0
a=extmap-allow-mixed
a=msid-semantic: WMS l91G3Ekmme9tlvEso1ApTqS6djaxtsamgfLu
m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 102 121 127 120 125 107 108 109 35 36 124 119 123
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:XEnc
a=ice-pwd:2PyQmLOm9YPPf1Pozvonticd
a=ice-options:trickle
a=fingerprint:sha-256 64:22:D7:93:FD:6C:A9:94:E3:65:76:B0:DB:4E:E9:8E:91:46:56:87:B1:E3:E9:B3:24:D0:CF:A5:3F:91:0A:FD
a=setup:actpass
a=mid:0
a=extmap:1 urn:ietf:params:rtp-hdrext:toffset
a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:3 urn:3gpp:video-orientation
a=extmap:4 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space
a=extmap:9 urn:ietf:params:rtp-hdrext:sdes:mid
a=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id
a=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id
a=sendrecv
a=msid:l91G3Ekmme9tlvEso1ApTqS6djaxtsamgfLu 7eb4296c-f3e4-4e95-9f6f-05aa386a3176
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 VP8/90000
a=rtcp-fb:96 goog-remb
a=rtcp-fb:96 transport-cc
a=rtcp-fb:96 ccm fir
a=rtcp-fb:96 nack
a=rtcp-fb:96 nack pli
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 VP9/90000
a=rtcp-fb:98 goog-remb
a=rtcp-fb:98 transport-cc
a=rtcp-fb:98 ccm fir
a=rtcp-fb:98 nack
a=rtcp-fb:98 nack pli
a=fmtp:98 profile-id=0
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 VP9/90000
a=rtcp-fb:100 goog-remb
a=rtcp-fb:100 transport-cc
a=rtcp-fb:100 ccm fir
a=rtcp-fb:100 nack
a=rtcp-fb:100 nack pli
a=fmtp:100 profile-id=2
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:102 H264/90000
a=rtcp-fb:102 goog-remb
a=rtcp-fb:102 transport-cc
a=rtcp-fb:102 ccm fir
a=rtcp-fb:102 nack
a=rtcp-fb:102 nack pli
a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f
a=rtpmap:121 rtx/90000
a=fmtp:121 apt=102
a=rtpmap:127 H264/90000
a=rtcp-fb:127 goog-remb
a=rtcp-fb:127 transport-cc
a=rtcp-fb:127 ccm fir
a=rtcp-fb:127 nack
a=rtcp-fb:127 nack pli
a=fmtp:127 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f
a=rtpmap:120 rtx/90000
a=fmtp:120 apt=127
a=rtpmap:125 H264/90000
a=rtcp-fb:125 goog-remb
a=rtcp-fb:125 transport-cc
a=rtcp-fb:125 ccm fir
a=rtcp-fb:125 nack
a=rtcp-fb:125 nack pli
a=fmtp:125 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtpmap:107 rtx/90000
a=fmtp:107 apt=125
a=rtpmap:108 H264/90000
a=rtcp-fb:108 goog-remb
a=rtcp-fb:108 transport-cc
a=rtcp-fb:108 ccm fir
a=rtcp-fb:108 nack
a=rtcp-fb:108 nack pli
a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f
a=rtpmap:109 rtx/90000
a=fmtp:109 apt=108
a=rtpmap:35 AV1X/90000
a=rtcp-fb:35 goog-remb
a=rtcp-fb:35 transport-cc
a=rtcp-fb:35 ccm fir
a=rtcp-fb:35 nack
a=rtcp-fb:35 nack pli
a=rtpmap:36 rtx/90000
a=fmtp:36 apt=35
a=rtpmap:124 red/90000
a=rtpmap:119 rtx/90000
a=fmtp:119 apt=124
a=rtpmap:123 ulpfec/90000
a=ssrc-group:FID 4173041010 2470630943
a=ssrc:4173041010 cname:VrEB0NYLt23UUzRD
a=ssrc:4173041010 msid:l91G3Ekmme9tlvEso1ApTqS6djaxtsamgfLu 7eb4296c-f3e4-4e95-9f6f-05aa386a3176
a=ssrc:4173041010 mslabel:l91G3Ekmme9tlvEso1ApTqS6djaxtsamgfLu
a=ssrc:4173041010 label:7eb4296c-f3e4-4e95-9f6f-05aa386a3176
a=ssrc:2470630943 cname:VrEB0NYLt23UUzRD
a=ssrc:2470630943 msid:l91G3Ekmme9tlvEso1ApTqS6djaxtsamgfLu 7eb4296c-f3e4-4e95-9f6f-05aa386a3176
a=ssrc:2470630943 mslabel:l91G3Ekmme9tlvEso1ApTqS6djaxtsamgfLu
a=ssrc:2470630943 label:7eb4296c-f3e4-4e95-9f6f-05aa386a3176

错误

现在的问题是,当我尝试设置这个远程描述时,这些错误会被抛出,我们永远不会尝试peerConnection.createAnswer

2021-11-12 13:45:52.819 26795-27780/au.com.australiandroid.androidclient D/CustomPeerConnectionObs: onSignalingChange: new signaling state is HAVE_REMOTE_OFFER
2021-11-12 13:45:52.820 26795-27780/au.com.australiandroid.androidclient E/SimpleSdpObserver: onSetFailure: failed to set the remote description: Failed to set remote offer sdp: Failed to set remote video description send parameters for m-section with mid='0'.
2021-11-12 13:45:52.820 26795-27780/au.com.australiandroid.androidclient E/MainActivity: onCreateFailure: failed to create answer: Session error code: ERROR_CONTENT. Session error description: Failed to set remote video description send parameters for m-section with mid='0'..

如果您有任何关于 setRemoteDescription 失败原因的信息,或者即使您对如何实现 Android WebRTC 客户端有任何建议,那么此时任何事情都会有所帮助。 我已经挣扎了几个星期,我不知道从哪里开始,因为谷歌搜索这个错误没有帮助。 要么是因为我根本不明白答案,要么是因为答案不相关。 我不知道,但请不要只是粘贴一个链接到 Google 上最热门的链接,因为我已经阅读了很多。

错误消息是由于包含 H264 编解码器的报价而触发的,而 Android 客户端并未预期 H264,并且未设置为编码和/或解码此特定硬件编码流。

解决方法是确保连接工厂的设置如下:

    private void createPeerConnectionFactory() {
        PeerConnectionFactory.InitializationOptions initializationOptions =
                PeerConnectionFactory.InitializationOptions.builder(this)
                        .createInitializationOptions();

        PeerConnectionFactory.initialize(initializationOptions);
        PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();

        VideoEncoderFactory encoderFactory = new DefaultVideoEncoderFactory(rootEglBase.getEglBaseContext(), true, true);
        VideoDecoderFactory decoderFactory = new DefaultVideoDecoderFactory(rootEglBase.getEglBaseContext());

        peerConnectionFactory = PeerConnectionFactory.builder()
                .setOptions(options)
                .setVideoDecoderFactory(decoderFactory)
                .setVideoEncoderFactory(encoderFactory)
                .createPeerConnectionFactory();

        List<PeerConnection.IceServer> iceServers = new ArrayList<>();
        PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
        createPeerConnection(rtcConfig);
    }

rootEglBase是建立较早通过定义类的活动可变private EglBase rootEglBase; 然后在活动的onCreate方法中使用EglBase.create()创建它的新实例。

peerConnectionFactory的实际获胜线是定义了encoderFactorydecoderFactory并指定了正确的标志来告诉 WebRTC 我们想要使用 h264HighProfile。

在这一行中可以看到: VideoEncoderFactory encoderFactory = new DefaultVideoEncoderFactory(rootEglBase.getEglBaseContext(), true, true);

其中第一个true布尔值是启用VP8编码,第二个是用于H264

一旦设置正确,它会在尝试setRemoteDescription时接受报价,并引导我走上正确的轨道,以解决我的代码中仍然存在的许多其他问题。

因此,如果您收到相同的错误消息,很可能是因为某种形式的硬件编码可能与 H264 有关。

如果你发现这个问题和我的回答并没有多大意义,那么就给我发个 PM 或评论这个答案,我会尽力帮助你让它工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM