我尝试解决此问题Why the function "onaddstream" is never called?
但是看起来像这样:
'rtcpeerconnection()'在webrtc的最新版本中不存在: “ org.webrtc:google-webrtc:1.0.28513”
我的onAddStream具有旧版本的回调。但是不再了
请帮助我
在回答@philip之后进行编辑
我无法覆盖peerObserver,Android Studio说:
类型为“ peerConnection.Observer”的表达式peerObserver不能为 作为函数调用。找不到函数“ invoke()”。
override fun runnerConnect(peerObserver: PeerConnection.Observer) {
Log.d("WebRTCClientCaster", "runnerConnect sdp ")
// mCurrentPeerConnection = mPeerConnectionFactory!!.createPeerConnection(IceServer.instance.listServers(), peerObserver)
val rtcConfig: PeerConnection.RTCConfiguration = PeerConnection.RTCConfiguration(IceServer.instance.listServers())
rtcConfig.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN
mCurrentPeerConnection = mPeerConnectionFactory!!.createPeerConnection(rtcConfig, peerObserver)
}
override fun runnerConnect(sdpObserver: SdpObserver) {
Log.d("WebRTCClientCaster", "runnerConnect peer")
// mCurrentPeerConnection!!.addStream(mLocalMS)
val mVideoTrack =
mPeerConnectionFactory?.createVideoTrack(WebRTCConstant.VIDEO_ID, mVideoSource)
mCurrentPeerConnection?.addTransceiver(mVideoTrack)
val mAudioTrack =
mPeerConnectionFactory?.createAudioTrack(WebRTCConstant.AUDIO_ID, mAudioSource)
mCurrentPeerConnection?.addTransceiver(mAudioTrack)
mCurrentPeerConnection!!.createOffer(sdpObserver, sdpConstraints)
}
我创建工厂和源代码的部分:
private fun setConfigurationOfCamera() {
Log.d("webRTCClientCaster", "setConfigurationOfCamera")
val options = PeerConnectionFactory.Options()
val defaultVideoEncoderFactory = DefaultVideoEncoderFactory(
this.mEglBase,
true,
true
)
val defaultVideoDecoderFactory = DefaultVideoDecoderFactory(this.mEglBase)
mPeerConnectionFactory = PeerConnectionFactory.builder()
.setOptions(options)
.setVideoEncoderFactory(defaultVideoEncoderFactory)
.setVideoDecoderFactory(defaultVideoDecoderFactory)
.createPeerConnectionFactory()
mLocalMS = mPeerConnectionFactory!!.createLocalMediaStream(WebRTCConstant.STREAM_LABEL)
if (mPeerConnectionParameters.isVideoCallEnabled) {
val surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", this.mEglBase)
videoCapturerAndroid = Capturer.getInstance().video
mVideoSource = mPeerConnectionFactory?.createVideoSource(videoCapturerAndroid!!.isScreencast)
videoCapturerAndroid?.initialize(surfaceTextureHelper, MyApp.getContext(), mVideoSource?.capturerObserver)
Capturer.getInstance().startCapture(
mPeerConnectionParameters.videoWidth,
mPeerConnectionParameters.videoHeight,
mPeerConnectionParameters.videoFps
)
// Add track to video capture with device
mLocalMS.addTrack(createVideoTrack(WebRTCConstant.VIDEO_ID, mVideoSource!!))
}
mAudioSource = mPeerConnectionFactory!!.createAudioSource(audioConstraints)
mLocalMS.addTrack(createAudioTrack(mAudioSource!!))
listener.onConfigurationReady()
}
用它代替我的注释,并用这段代码说一个人:
# Fatal error in: ../../../../usr/local/google/home/sakal/code/webrtc-aar-release/src/pc/peer_connection.cc, line 1240
# last system error: 0
# Check failed: !IsUnifiedPlan()
# AddStream is not available with Unified Plan SdpSemantics. Please use AddTrack instead.
2019-09-23 12:53:07.223 4804-6057/com.Dazzl.debug A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 6057 (signaling_threa)
答案 0 :(得分:0)
尝试执行此操作。请注意,onTrack是在PeerConnectionObserver(pcObserver)中实现的,而不是peerConnection本身:
PeerConnection.RTCConfiguration rtcConfig =
new PeerConnection.RTCConfiguration(mIceServers);
rtcConfig.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;
//Unified Plan is the new standard for SDP semantics and is needed to use transceivers
peerConnection = factory.createPeerConnection(rtcConfig, new PcObserver("localPeerCreation")
{
@Override
public void onTrack(RtpTransceiver transceiver) {
showToast(getString(R.string.onReceivedTrackToastMessage));
super.onTrack(transceiver);
gotRemoteTrack(transceiver);
}
});
//Somewhere else in your code, where you create the local video track...
localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
peerConnection.addTransceiver(localVideoTrack);
peerConnection.addTransceiver(localAudioTrack);
///在一个单独的类中,创建一个从PeerConnection.Observer继承的PeerConnectionObserver ...
public class PcObserver implements PeerConnection.Observer {
private String logTag;
CustomPeerConnectionObserver(String logTag) {
this.logTag = logTag
}
@Override
public void onSignalingChange(PeerConnection.SignalingState signalingState) {
Log.d(logTag, "onSignalingChange() called with: signalingState = [" + signalingState + "]");
}
//....
}