Java Code Examples for org.webrtc.SurfaceViewRenderer#init()

The following examples show how to use org.webrtc.SurfaceViewRenderer#init() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From webrtc-android-tutorial with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // create PeerConnectionFactory
    PeerConnectionFactory.InitializationOptions initializationOptions =
            PeerConnectionFactory.InitializationOptions.builder(this).createInitializationOptions();
    PeerConnectionFactory.initialize(initializationOptions);
    PeerConnectionFactory peerConnectionFactory = PeerConnectionFactory.builder().createPeerConnectionFactory();

    // create AudioSource
    AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints());
    AudioTrack audioTrack = peerConnectionFactory.createAudioTrack("101", audioSource);

    EglBase.Context eglBaseContext = EglBase.create().getEglBaseContext();

    SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBaseContext);
    // create VideoCapturer
    VideoCapturer videoCapturer = createCameraCapturer();
    VideoSource videoSource = peerConnectionFactory.createVideoSource(videoCapturer.isScreencast());
    videoCapturer.initialize(surfaceTextureHelper, getApplicationContext(), videoSource.getCapturerObserver());
    videoCapturer.startCapture(480, 640, 30);

    SurfaceViewRenderer localView = findViewById(R.id.localView);
    localView.setMirror(true);
    localView.init(eglBaseContext, null);

    // create VideoTrack
    VideoTrack videoTrack = peerConnectionFactory.createVideoTrack("100", videoSource);
    // display in localView
    videoTrack.addSink(localView);
}
 
Example 2
Source File: Peer.java    From webrtc_android with MIT License 6 votes vote down vote up
public void createRender(EglBase mRootEglBase, Context context, boolean isOverlay) {
    renderer = new SurfaceViewRenderer(context);
    renderer.init(mRootEglBase.getEglBaseContext(), new RendererCommon.RendererEvents() {
        @Override
        public void onFirstFrameRendered() {
            Log.d(TAG, "createRender onFirstFrameRendered");

        }

        @Override
        public void onFrameResolutionChanged(int videoWidth, int videoHeight, int rotation) {
            Log.d(TAG, "createRender onFrameResolutionChanged");
        }
    });
    renderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    renderer.setMirror(true);
    renderer.setZOrderMediaOverlay(isOverlay);
    sink = new ProxyVideoSink();
    sink.setTarget(renderer);
    if (_remoteStream != null && _remoteStream.videoTracks.size() > 0) {
        _remoteStream.videoTracks.get(0).addSink(sink);
    }

}
 
Example 3
Source File: CustomWebSocketListener.java    From WebRTCapp with Apache License 2.0 6 votes vote down vote up
private void createVideoView(final RemoteParticipant remoteParticipant) {
    Handler mainHandler = new Handler(videoConferenceActivity.getMainLooper());

    Runnable myRunnable = new Runnable() {
        @Override
        public void run() {
            View rowView = videoConferenceActivity.getLayoutInflater().inflate(R.layout.peer_video, null);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(0, 0, 0, 20);
            rowView.setLayoutParams(lp);
            int rowId = View.generateViewId();
            rowView.setId(rowId);
            views_container.addView(rowView);
            SurfaceViewRenderer videoView = (SurfaceViewRenderer)((ViewGroup)rowView).getChildAt(0);
            remoteParticipant.setVideoView(videoView);
            videoView.setMirror(false);
            EglBase rootEglBase = EglBase.create();
            videoView.init(rootEglBase.getEglBaseContext(), null);
            videoView.setZOrderMediaOverlay(true);
            View textView = ((ViewGroup)rowView).getChildAt(1);
            remoteParticipant.setParticipantNameText((TextView) textView);
            remoteParticipant.setView(rowView);
        }
    };
    mainHandler.post(myRunnable);
}
 
Example 4
Source File: MainActivity.java    From owt-client-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onReady(final SurfaceViewRenderer localRenderer,
        final SurfaceViewRenderer remoteRenderer) {
    this.localRenderer = localRenderer;
    this.remoteRenderer = remoteRenderer;
    localRenderer.init(rootEglBase.getEglBaseContext(), null);
    remoteRenderer.init(rootEglBase.getEglBaseContext(), null);

    executor.execute(() -> {
        if (capturer == null) {
            boolean vga = settingsFragment == null || settingsFragment.resolutionVGA;
            boolean isCameraFront = settingsFragment == null || settingsFragment.cameraFront;
            capturer = OwtVideoCapturer.create(vga ? 640 : 1280, vga ? 480 : 720, 30, true, isCameraFront);
            localStream = new LocalStream(capturer,
                    new MediaConstraints.AudioTrackConstraints());
        }
        localStream.attach(localRenderer);
        if (remoteStream != null && !remoteStreamEnded) {
            remoteStream.attach(remoteRenderer);
        }
    });
}
 
Example 5
Source File: MainActivity.java    From janus-gateway-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    rootView = (LinearLayout) findViewById(R.id.activity_main);
    mWebSocketChannel = new WebSocketChannel();
    mWebSocketChannel.initConnection("ws://xxx:xxx");
    mWebSocketChannel.setDelegate(this);

    createLocalRender();
    remoteRender = (SurfaceViewRenderer) findViewById(R.id.remote_video_view);
    remoteRender.init(rootEglBase.getEglBaseContext(), null);
    peerConnectionParameters  = new PeerConnectionParameters(false, 360, 480, 20, "H264", true, 0, "opus", false, false, false, false, false);
    peerConnectionClient = PeerConnectionClient.getInstance();
    peerConnectionClient.createPeerConnectionFactory(this, peerConnectionParameters, this);
}
 
Example 6
Source File: RCConnection.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
private void initializeVideo(boolean videoEnabled, PercentFrameLayout localRenderLayout, PercentFrameLayout remoteRenderLayout)
{
   if (localRenderLayout == null ||remoteRenderLayout == null) {
      return;
   }

   scalingType = ScalingType.SCALE_ASPECT_FILL;

   this.localRenderLayout = localRenderLayout;
   this.remoteRenderLayout = remoteRenderLayout;

   localRender = (SurfaceViewRenderer)localRenderLayout.getChildAt(0);
   remoteRender = (SurfaceViewRenderer)remoteRenderLayout.getChildAt(0);

   localRender.init(peerConnectionClient.getRenderContext(), null);
   localRender.setZOrderMediaOverlay(true);
   remoteRender.init(peerConnectionClient.getRenderContext(), null);
   updateVideoView(VideoViewState.NONE);
}
 
Example 7
Source File: WebRTCEngine.java    From webrtc_android with MIT License 5 votes vote down vote up
@Override
public View startPreview(boolean isOverlay) {
    localRenderer = new SurfaceViewRenderer(mContext);
    localRenderer.init(mRootEglBase.getEglBaseContext(), null);
    localRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    localRenderer.setMirror(true);
    localRenderer.setZOrderMediaOverlay(isOverlay);

    localSink = new ProxyVideoSink();
    localSink.setTarget(localRenderer);
    if (_localStream.videoTracks.size() > 0) {
        _localStream.videoTracks.get(0).addSink(localSink);
    }
    return localRenderer;
}
 
Example 8
Source File: RtpSessionActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private void ensureSurfaceViewRendererIsSetup(final SurfaceViewRenderer surfaceViewRenderer) {
    surfaceViewRenderer.setVisibility(View.VISIBLE);
    try {
        surfaceViewRenderer.init(requireRtpConnection().getEglBaseContext(), null);
    } catch (IllegalStateException e) {
        Log.d(Config.LOGTAG, "SurfaceViewRenderer was already initialized");
    }
    surfaceViewRenderer.setEnableHardwareScaler(true);
}
 
Example 9
Source File: RtpSessionActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void ensureSurfaceViewRendererIsSetup(final SurfaceViewRenderer surfaceViewRenderer) {
    surfaceViewRenderer.setVisibility(View.VISIBLE);
    try {
        surfaceViewRenderer.init(requireRtpConnection().getEglBaseContext(), null);
    } catch (IllegalStateException e) {
        Log.d(Config.LOGTAG, "SurfaceViewRenderer was already initialized");
    }
    surfaceViewRenderer.setEnableHardwareScaler(true);
}
 
Example 10
Source File: MainActivity.java    From janus-gateway-android with MIT License 4 votes vote down vote up
private void createLocalRender() {
    localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view);
    rootEglBase = EglBase.create();
    localRender.init(rootEglBase.getEglBaseContext(), null);
    localRender.setEnableHardwareScaler(true);
}
 
Example 11
Source File: VideoActivity.java    From VideoCRE with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_video);

    VideoConfig config = VideoConfig.builder()
            .previewWidth(1280)
            .previewHeight(720)
            .outputWidth(448)
            .outputHeight(800)
            .fps(30)
            .outputBitrate(800)
            .build();
    VideoConfig hdConfig = VideoConfig.builder()
            .previewWidth(1280)
            .previewHeight(720)
            .outputWidth(720)
            .outputHeight(1280)
            .fps(30)
            .outputBitrate(2000)
            .build();
    VideoCapturer capturer = createVideoCapturer();

    mVideoView = (SurfaceViewRenderer) findViewById(R.id.mVideoView1);
    try {
        String filename = "video_source_record_" + System.currentTimeMillis();
        mMp4Recorder = new Mp4Recorder(
                new File(Environment.getExternalStorageDirectory(), filename + ".mp4"));
        mHdMp4Recorder = new Mp4Recorder(
                new File(Environment.getExternalStorageDirectory(), filename + "-hd.mp4"));
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(this, "start Mp4Recorder fail!", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    mHwAvcEncoder = new HwAvcEncoder(config, mMp4Recorder);
    mHdHwAvcEncoder = new HwAvcEncoder(hdConfig, mHdMp4Recorder);
    mVideoSink = new VideoSink(mVideoView, mHwAvcEncoder, mHdHwAvcEncoder);
    mVideoSource = new VideoSource(getApplicationContext(), config, capturer, mVideoSink);

    mVideoView.init(mVideoSource.getRootEglBase().getEglBaseContext(), null);
    mHwAvcEncoder.start(mVideoSource.getRootEglBase());
    mHdHwAvcEncoder.start(mVideoSource.getRootEglBase());

    initView();
}