如何在Android / Webrtc / PeerConnection / createOffer中修复“ m = video 9 UDP / TLS / RTP / SAVPF 0”问题

时间:2019-04-12 09:01:56

标签: android video-streaming webrtc sdp peer-connection

如何获取/启用webrtc /视频编码格式? ( Android

我正在尝试使用media / vidio创建sdp-offer,但似乎没有返回fmt支持:

m=video 9 UDP/TLS/RTP/SAVPF 0

它可以在一个应用程序(2个对等连接)中处理数据通道和音频流。

部分代码:

// Media Constraint
MediaConstraints pcConstraints = new MediaConstraints();
pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveAudio", "true"));
pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveVideo", "true"));

MediaStream mediaStream = factory.createLocalMediaStream("MediaStream-"+name);
// Audio
AudioSource audioSource = factory.createAudioSource(new MediaConstraints());
mediaStream.addTrack(factory.createAudioTrack("Audio-"+name, audioSource));
// Video
videoTrackFromCamera = createVideoTrackFromCamera("Video-"+name);
if(videoTrackFromCamera!=null){
    surfaceViewRenderer.init(rootEglBase.getEglBaseContext(), null);
    surfaceViewRenderer.setMirror(true);
    surfaceViewRenderer.setEnableHardwareScaler(true);
    surfaceViewRenderer.setEnabled(true);
    videoTrackFromCamera.addSink(surfaceViewRenderer);
    mediaStream.addTrack(videoTrackFromCamera);
}

pc.addStream(mediaStream);
pc.createAnswer(sdpObserver, pcConstraints);

onCreateSuccess(SessionDescription),类型=要约,描述:

v=0
o=- 1829788378060179036 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video data
a=msid-semantic: WMS MediaStream-First
m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 102 0 8 106 105 13 110 112 113 126
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:Muza
a=ice-pwd:npxXusvEWRQtpS/hjmAoPGn+
a=ice-options:trickle renomination
a=fingerprint:sha-256 79:5F:F6:2A:42:53:41:38:C4:EC:15:0D:4E:D1:6C:3A:66:39:57:2B:78:BE:5B:2D:70:94:96:AA:98:86:D4:B1
a=setup:actpass
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
a=extmap:2 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=sendrecv
a=rtcp-mux
a=rtpmap:111 opus/48000/2
a=rtcp-fb:111 transport-cc
a=fmtp:111 minptime=10;useinbandfec=1
a=rtpmap:103 ISAC/16000
a=rtpmap:104 ISAC/32000
a=rtpmap:9 G722/8000
a=rtpmap:102 ILBC/8000
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:110 telephone-event/48000
a=rtpmap:112 telephone-event/32000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:3451329273 cname:Jjbwj2+OSGEvw+Xc
a=ssrc:3451329273 msid:MediaStream-First Audio-First
a=ssrc:3451329273 mslabel:MediaStream-First
a=ssrc:3451329273 label:Audio-First
m=video 9 UDP/TLS/RTP/SAVPF 0
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:Muza
a=ice-pwd:npxXusvEWRQtpS/hjmAoPGn+
a=ice-options:trickle renomination
a=fingerprint:sha-256 79:5F:F6:2A:42:53:41:38:C4:EC:15:0D:4E:D1:6C:3A:66:39:57:2B:78:BE:5B:2D:70:94:96:AA:98:86:D4:B1
a=setup:actpass
a=mid:video
a=extmap:14 urn:ietf:params:rtp-hdrext:toffset
a=extmap:13 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:3 urn:3gpp:video-orientation
a=extmap:2 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://tools.ietf.org/html/draft-ietf-avtext-framemarking-07
a=extmap:9 http://www.webrtc.org/experiments/rtp-hdrext/color-space
a=sendrecv
a=rtcp-mux
a=rtcp-rsize
a=ssrc:2429683820 cname:Jjbwj2+OSGEvw+Xc
a=ssrc:2429683820 msid:MediaStream-First Video-First
a=ssrc:2429683820 mslabel:MediaStream-First
a=ssrc:2429683820 label:Video-First
m=application 9 DTLS/SCTP 5000
c=IN IP4 0.0.0.0
a=ice-ufrag:Muza
a=ice-pwd:npxXusvEWRQtpS/hjmAoPGn+
a=ice-options:trickle renomination
a=fingerprint:sha-256 79:5F:F6:2A:42:53:41:38:C4:EC:15:0D:4E:D1:6C:3A:66:39:57:2B:78:BE:5B:2D:70:94:96:AA:98:86:D4:B1
a=setup:actpass
a=mid:data
a=sctpmap:5000 webrtc-datachannel 1024

1 个答案:

答案 0 :(得分:1)

似乎在创建PeerConnectionFactory时必须设置VideoDecoderFactoryVideoEncoderFactory

WebRTCPeerConnectionDelegate(Context context) {
    this.context = context;
    PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(this.context)
            .setEnableInternalTracer(false)
            .createInitializationOptions());
    EglBase.Context eglContext = EglBase.create().getEglBaseContext();
    VideoDecoderFactory videoDecoderFactory = new DefaultVideoDecoderFactory(eglContext);
    VideoEncoderFactory videoEncoderFactory = new DefaultVideoEncoderFactory(eglContext, true, true);
    peerConnectionFactory = PeerConnectionFactory.builder()
            .setVideoDecoderFactory(videoDecoderFactory)
            .setVideoEncoderFactory(videoEncoderFactory)
            .createPeerConnectionFactory();
}