【问题标题】:App is getting crash on continuous pausing and starting video stream using PJSIP应用程序在使用 PJSIP 连续暂停和启动视频流时崩溃
【发布时间】:2026-02-24 01:55:02
【问题描述】:

如果我在进行视频通话时连续暂停和启动,我的应用程序会崩溃我使用以下代码暂停和恢复视频流。

PJSIP 版本:2.9

func pauseVideo(_ value: Bool) {
    guard let id = SIPAccount.account?.calls.last?.call_id else { return }
    let operation = value ? PJSUA_CALL_VID_STRM_STOP_TRANSMIT : PJSUA_CALL_VID_STRM_START_TRANSMIT

    var param = pjsua_call_vid_strm_op_param()
    pjsua_call_vid_strm_op_param_default(&param)
    param.med_idx = pjsua_call_get_vid_stream_idx(pjsua_call_id(id))
    param.dir = value ? PJMEDIA_DIR_NONE : PJMEDIA_DIR_ENCODING_DECODING

    pjsua_call_set_vid_strm(pjsua_call_id(id), operation, &param)
}

日志:

PJSIP_log: in pauseVideo
pjsua_vid.c  Call 0: set video stream, op=5
vid_conf.c  .Updating render state for port id 2 (1 sources)..
vid_conf.c  .Created render state for connection 3->2
vid_conf.c  .src#0=BGRA/352x288->352x264@0,12 dst=320x240@0,0
vid_conf.c  .Port 3 (Front Camera) transmitting to port 2 (vstenc0x12c093028)
vstenc0x12c093028  .Encoder stream resumed
PJSIP_log: video pause status 0
vstenc0x12c093028 !Forcing encoder to generate keyframe
PJSIP_log: in pauseVideo
pjsua_vid.c !Call 0: set video stream, op=6
vstenc0x12c093028  .Encoder stream paused
vid_conf.c  .Cleaned up render state for connection 3->2
vid_conf.c  .Port 3 (Front Camera) stop transmitting to port 2 (vstenc0x12c093028)
PJSIP_log: video pause status 0
silencedet.c !Re-adjust threshold (in silence)to 0
PJSIP_log: in pauseVideo
pjsua_vid.c !Call 0: set video stream, op=5
strm0x12ca03228 !Jitter buffer starts returning normal frames (after 249 empty/lost)
strm0x12ca03228  Jitter buffer empty (prefetch=0), plc invoked
strm0x12ca03228  Start talksprut..
strm0x12ca03228  Starting silence
silencedet.c  Re-adjust threshold (in silence)to 0

pjsua_vid.c !Call 0: set video stream, op=5 应用程序挂起之后,这 3 行将被记录多次

strm0x12ca03228  Start talksprut..
strm0x12ca03228  Starting silence
silencedet.c  Re-adjust threshold (in silence)to 0

【问题讨论】:

  • 请用 PJSIP 版本更新问题,以及附加日志和调用堆栈/堆栈跟踪。
  • 首先,确保您没有在 iOS 上使用 gcd (trac.pjsip.org/repos/wiki/Getting-Started/iPhone#gcd-crash)。然后,还提供堆栈跟踪,以便我们可以知道究竟是哪个函数发生了崩溃。
  • @SauwMingLiong 使用 pjsua_schedule_timer2() 解决了我的问题,非常感谢您的帮助。 :)
  • @Devansh Vyas 我在启动和停止电车时遇到同样的问题,我在哪里可以使用 pjsua_schedule_timer2
  • @SonPham 我遇到了暂停视频的问题,可以通过以下方式解决:func pauseVideo(_ value: Bool) { let valuePointer = UnsafeMutablePointer<Int8>(mutating: (value.description as NSString).utf8String) let valueRawPointer = UnsafeMutableRawPointer.init(valuePointer) pjsua_schedule_timer2(pauseCallback, valueRawPointer, 0) print("PJSIP_log: in pauseVideo") }

标签: ios swift voip pjsip


【解决方案1】:

使用pjsua_schedule_timer2() 解决了这个问题

【讨论】:

  • 如果您能告诉我如何在 Android 中实现 puase 和启动视频流,那将是非常有帮助的......我无法实现它...... *.com/questions/63702759/…
  • 我对 Android 了解不多,但会分享给一位可以指导您的开发人员。
  • 我在视频通话中尝试用 200 回答时崩溃了。我遇到了 ICE 的问题。请帮我解答接听电话 (spinics.net/lists/pjsip/msg20839.html)