4

在 android 和 iOs 之间调用时使用 SurfaceViewRenderer 显示远程视频轨道时遇到问题(android <-> android 和 ios<->ios 也可以)

Android 上的远程视频视图将在几秒钟后冻结,但音频仍然有效(iOS 没问题)。

可能是iOS的H264编解码器导致的问题,但是我按照最新的code进行decode和encode PeerConnection,所以还是卡在这里。

下面是我的代码:

创建PeerConnectionFactory

 PeerConnectionFactory.initialize(
                PeerConnectionFactory.InitializationOptions.builder(activity.getApplicationContext())
                        .setEnableInternalTracer(true)
                        .setEnableVideoHwAcceleration(true, true)
                        .createInitializationOptions());

解码和编码

 private void tryingToCreatePeerConnectionFactory(EglBase eglBase) {
        final PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
        final DefaultVideoEncoderFactory encoderFactory = new DefaultVideoEncoderFactory(eglBase.getEglBaseContext(), true, true);
        final DefaultVideoDecoderFactory decoderFactory = new DefaultVideoDecoderFactory(eglBase.getEglBaseContext());
        peerConnectionFactory = PeerConnectionFactory.builder().setOptions(options).
                setVideoDecoderFactory(decoderFactory).
                setVideoEncoderFactory(encoderFactory).
                createPeerConnectionFactory();
    }

SDP 内容

v=0
o=- 3807425029370800822 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE audio video
a=msid-semantic: WMS ARDAMS
m=audio 9 UDP/TLS/RTP/SAVPF 111 103 9 102 0 8 105 13 110 113 126
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:pTq5
a=ice-pwd:EVfiXQOe4/G/01ezOXYv1fzB
a=ice-options:trickle renomination
a=fingerprint:sha-256 A3:D1:0B:D4:9F:A9:ED:C5:D2:94:04:F3:91:07:6F:FD:68:71:4C:7B:CA:87:3F:AB:34:B5:F3:7E:82:0B:42:77
a=setup:active
a=mid:audio
a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level
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:9 G722/8000
a=rtpmap:102 ILBC/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:105 CN/16000
a=rtpmap:13 CN/8000
a=rtpmap:110 telephone-event/48000
a=rtpmap:113 telephone-event/16000
a=rtpmap:126 telephone-event/8000
a=ssrc:3210082304 cname:PPyVOHEaYgrfSyKM
a=ssrc:3210082304 msid:ARDAMS ARDAMSa0
a=ssrc:3210082304 mslabel:ARDAMS
a=ssrc:3210082304 label:ARDAMSa0
m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 127
c=IN IP4 0.0.0.0
a=rtcp:9 IN IP4 0.0.0.0
a=ice-ufrag:pTq5
a=ice-pwd:EVfiXQOe4/G/01ezOXYv1fzB
a=ice-options:trickle renomination
a=fingerprint:sha-256 A3:D1:0B:D4:9F:A9:ED:C5:D2:94:04:F3:91:07:6F:FD:68:71:4C:7B:CA:87:3F:AB:34:B5:F3:7E:82:0B:42:77
a=setup:active
a=mid:video
a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
a=extmap:4 urn:3gpp:video-orientation
a=extmap:5 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01
a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay
a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type
a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/video-timing
a=sendrecv
a=rtcp-mux
a=rtcp-rsize
a=rtpmap:96 H264/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=fmtp:96 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640c1f
a=rtpmap:97 rtx/90000
a=fmtp:97 apt=96
a=rtpmap:98 H264/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 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f
a=rtpmap:99 rtx/90000
a=fmtp:99 apt=98
a=rtpmap:100 red/90000
a=rtpmap:101 rtx/90000
a=fmtp:101 apt=100
a=rtpmap:127 ulpfec/90000
a=ssrc-group:FID 2423939598 98025098
a=ssrc:2423939598 cname:PPyVOHEaYgrfSyKM
a=ssrc:2423939598 msid:ARDAMS ARDAMSv0
a=ssrc:2423939598 mslabel:ARDAMS
a=ssrc:2423939598 label:ARDAMSv0
a=ssrc:98025098 cname:PPyVOHEaYgrfSyKM
a=ssrc:98025098 msid:ARDAMS ARDAMSv0
a=ssrc:98025098 mslabel:ARDAMS
a=ssrc:98025098 label:ARDAMSv0

更新 我们找到了这个问题的原因,由于未知的原因,在 Android 端接收到的数据变低并且不再上升,这就是为什么视频被冻结

以下是视频冻结时收到的日期值

getBytesInInterval= 6091

但我不知道为什么会这样

有人对我的问题有建议吗?任何回应将不胜感激。

4

2 回答 2

2

我已经关注了这个链接,我认为这可能会有所帮助,伙计。

  if (options != null) {
  Log.d(TAG, "Factory networkIgnoreMask option: " + options.networkIgnoreMask);
}
final boolean enableH264HighProfile =
    VIDEO_CODEC_H264_HIGH.equals(peerConnectionParameters.videoCodec);
final VideoEncoderFactory encoderFactory;
final VideoDecoderFactory decoderFactory;

if (peerConnectionParameters.videoCodecHwAcceleration) {
  encoderFactory = new DefaultVideoEncoderFactory(
      rootEglBase.getEglBaseContext(), true /* enableIntelVp8Encoder */, enableH264HighProfile);
  decoderFactory = new DefaultVideoDecoderFactory(rootEglBase.getEglBaseContext());
} else {
  encoderFactory = new SoftwareVideoEncoderFactory();
  decoderFactory = new SoftwareVideoDecoderFactory();
}

factory = PeerConnectionFactory.builder()
              .setOptions(options)
              .setAudioDeviceModule(adm)
              .setVideoEncoderFactory(encoderFactory)
              .setVideoDecoderFactory(decoderFactory)
              .createPeerConnectionFactory();

这是来自 WebRTC for android 的官方文档/代码。

于 2019-04-25T02:59:12.313 回答
1

更新

我已经找到了这个问题的解决方案,伙计。根本原因来自 iOS 大小,每个视频编解码器(解码/编码)的分辨率应该按比例缩小,并且冻结帧情况将消失。

请为 iOS 端更新此代码

static let videoResolutionsStaticValues = [ "640x480", "960x540", "1280x720" ]
static let videoCodecsStaticValues = [ "H264", "VP8", "VP9" ]
于 2019-05-07T07:13:06.543 回答