簡體   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