android WebRTC远程视频在几秒钟后冻结

iih3973s  于 2023-05-12  发布在  Android
关注(0)|答案(3)|浏览(250)

我在使用SurfaceViewRenderer在Android和iOS之间调用时显示远程视频轨道时遇到了一个问题(Android <->Android和iOS <->iOS也可以工作)
Android上的远程视频视图将在几秒钟后冻结,但音频仍然工作,(iOS是好的)。
也许是iOS的H264编解码器造成的问题,但我遵循最新的代码来解码和编码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

但我不知道为什么会这样
有人对我的问题有建议吗?如有任何答复,将不胜感激。

j5fpnvbx

j5fpnvbx1#

我已经点击了这个链接,我想这可能有帮助,伙计。

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();

It's official document/code from WebRTC for android.

cwxwcias

cwxwcias2#

更新

我已经找到解决这个问题的办法了。根本原因来自iOS尺寸,每个视频编解码器(解码/编码)的分辨率应按比例缩小,冻结帧情况将消失。
请将此代码更新为iOS端

static let videoResolutionsStaticValues = [ "640x480", "960x540", "1280x720" ]
static let videoCodecsStaticValues = [ "H264", "VP8", "VP9" ]
p5fdfcr1

p5fdfcr13#

从iOS发送的决议是它在我的情况下导致问题的原因。要应用解决方案,您需要将它们设置为媒体约束:

let constraints = [
    "minWidth": Self.videoResolutionsStaticValues[0],
    "maxWidth": Self.videoResolutionsStaticValues[2],
    "minHeight": "480",
    "maxHeight": "720"
]
RTCMediaConstraints(mandatoryConstraints: constraints, optionalConstraints: nil)

但最重要的是,您应该直接使用AVCaptureSession和AVCaptureDevice配置视频捕获会话的分辨率

// Set the desired video resolution
let targetResolution = CGSize(width: 640, height: 480)

if let format = videoDevice!.formats.first(where: { format -> Bool in
    let dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription)
    return dimensions.width == Int32(targetResolution.width) && dimensions.height == Int32(targetResolution.height)
}) {
    do {
        try videoDevice!.lockForConfiguration()
        videoDevice!.activeFormat = format
        videoDevice!.unlockForConfiguration()
    } catch {
        print("Error setting the video device active format")
    }
}

captureSession.sessionPreset = .hd1280x720

有了这些变化,视频应该不会再冻结了

相关问题