ScreenCapturerAndroid без надстройки - PullRequest
0 голосов
/ 20 сентября 2019

Я пытаюсь создать приложение для обмена экранами с помощью WebRTC.Все работает как положено, но мне нужно позвонить в addSing со стоком.Единственным приемником, который работал, был SurfaceViewRenderer.

    VideoTrack videoTrack = mPeerConnectionFactory.createVideoTrack("100", videoSource);
    SurfaceViewRenderer localView = mChatHeadView.findViewById(R.id.localView);
    localView.setMirror(true);
    localView.init(mEglBaseContext, null);

    videoTrack.addSink(localView);

Я хочу, чтобы он работал без отображения локального потока в приложении.

Спасибо

больше кода: init:PeerConnectionFactory.initialize (PeerConnectionFactory.InitializationOptions.builder (this) .createInitializationOptions ());

    PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();

    DefaultVideoEncoderFactory defaultVideoEncoderFactory new DefaultVideoEncoderFactory(mEglBaseContext, true, true);

    DefaultVideoDecoderFactory defaultVideoDecoderFactory = new DefaultVideoDecoderFactory(mEglBaseContext);

    mPeerConnectionFactory = PeerConnectionFactory.builder()
            .setOptions(options)
            .setVideoEncoderFactory(defaultVideoEncoderFactory)
            .setVideoDecoderFactory(defaultVideoDecoderFactory)
            .createPeerConnectionFactory();

    SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("sThread", mEglBaseContext);

    VideoCapturer videoCapturer = createScreenCapturer();//usign org.webrtc.ScreenCapturerAndroid
    VideoSource videoSource = mPeerConnectionFactory.createVideoSource(videoCapturer.isScreencast());

    videoCapturer.initialize( surfaceTextureHelper, getApplicationContext(), videoSource.getCapturerObserver() );

    videoCapturer.startCapture(mScreenW, mScreenH, 30);

    VideoTrack videoTrack = mPeerConnectionFactory.createVideoTrack("100", videoSource);
    SurfaceViewRenderer localView = mChatHeadView.findViewById(R.id.localView);
    localView.setMirror(true);
    localView.init(mEglBaseContext, null);

// если я это закомментирую, то ничего не будет работать на другой стороне канала videoTrack.addSink (localView);

    mMediaStream = mPeerConnectionFactory.createLocalMediaStream("mediaStream");
    mMediaStream.addTrack(videoTrack);

    mSignalingClient = new SignalingClient();
    mSignalingClient.init(this,mServURI);

//create the connection:
private PeerConnection getConnection() {
    PeerConnection peerConnection = mPeerConnectionFactory.createPeerConnection(mIceServers, new PeerConnectionAdapter() {
        @Override
        public void onIceCandidate(IceCandidate iceCandidate) {
            super.onIceCandidate(iceCandidate);
            try {
                mSignalingClient.sendIceCandidate(iceCandidate, socketId);
            }
            catch (Exception e){
                showError("",e);
            }
        }

        @Override
        public void onAddStream(MediaStream mediaStream) {
            super.onAddStream(mediaStream);
        }
    });

    peerConnection.addStream(mMediaStream);

    return peerConnection;
}

public void onOfferReceived(JSONObject data){
    PeerConnection peerConnection = getConnection();

    ....
    //set remote description
    peerConnection.setRemoteDescription(
            new SdpAdapter(),
            new SessionDescription(SessionDescription.Type.OFFER, sdpData)
    );

    peerConnection.createAnswer(new SdpAdapter() {
        @Override
        public void onCreateSuccess(SessionDescription sdp) {
            super.onCreateSuccess(sdp);
            mPeerConnectionMap.get(socketId).setLocalDescription(new SdpAdapter(),sdp);
            .....
        }
    }, new MediaConstraints());
}

1 Ответ

0 голосов
/ 22 сентября 2019

Я бы попробовал вместо

mMediaStream = mPeerConnectionFactory.createLocalMediaStream("mediaStream");
    mMediaStream.addTrack(videoTrack);

Вместо этого:

            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

    RtpTransceiver.RtpTransceiverInit initOptions = new RtpTransceiver.RtpTransceiverInit(RtpTransceiver.RtpTransceiverDirection.SEND_ONLY);

peerConnection = mPeerConnectionFactory.createPeerConnection(rtcConfig, 
                     new PeerConnection.Observer("tag"){

                           @Override
                           public void onIceCandidate(IceCandidate iceCandidate) {
                           super.onIceCandidate(iceCandidate);
                           try {
                               mSignalingClient.sendIceCandidate(iceCandidate, socketId);
                                }
                               catch (Exception e){
                               showError("",e);
                               } 
                           }
                     }

    peerConnection.addTransceiver(videoTrack);

Я считаю, что addTransceiver - это новый способ сделать это, а не onAddStream.На стороне браузера вам придется использовать onTrack.Эта ссылка содержит примеры использования трансиверов и onTrack в JS.Я не уверен, решит ли это вашу проблему, но по крайней мере вы будете делать это по-новому.Также, совершенно не по теме, я упомяну, что веб-браузер iOS, похоже, еще не поддерживает WebRTC.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...