Java Code Examples for org.webrtc.EglBase#Context

The following examples show how to use org.webrtc.EglBase#Context . 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: WebRtcClient.java    From imsdk-android with MIT License 6 votes vote down vote up
public Peer(EglBase.Context context) {
            PeerConnection.RTCConfiguration rtcConfig =
                    new PeerConnection.RTCConfiguration(iceServers);
            if(pcParams.videoCallEnabled) {
                factory.setVideoHwAccelerationOptions(context, context);
            }
//            rtcConfig.iceTransportsType = PeerConnection.IceTransportsType.ALL;
            rtcConfig.iceTransportsType = PeerConnection.IceTransportsType.RELAY;
            //禁用TCP, turn服务器ice协议使用UDP
            rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.ENABLED;
            rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
            rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.NEGOTIATE;
            rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
            // Use ECDSA encryption.
            rtcConfig.keyType = PeerConnection.KeyType.ECDSA;
            this.pc = factory.createPeerConnection(rtcConfig, pcConstraints, this);
            pc.addStream(localMS);
            if(mListener != null)
                mListener.onStatusChanged(WebRTCStatus.CONNECTING);
        }
 
Example 3
Source File: PeerConnectionClient.java    From janus-gateway-android with MIT License 6 votes vote down vote up
private void createPeerConnectionInternal(EglBase.Context renderEGLContext, BigInteger handleId) {
  if (factory == null || isError) {
    Log.e(TAG, "Peerconnection factory is not created");
    return;
  }

  Log.d(TAG, "PCConstraints: " + pcConstraints.toString());

  Log.d(TAG, "EGLContext: " + renderEGLContext);
  factory.setVideoHwAccelerationOptions(renderEGLContext, renderEGLContext);

  PeerConnection peerConnection = createPeerConnection(handleId, true);

  mediaStream = factory.createLocalMediaStream("ARDAMS");
  mediaStream.addTrack(createVideoTrack(videoCapturer));

  mediaStream.addTrack(createAudioTrack());
  peerConnection.addStream(mediaStream);
  findVideoSender(handleId);
}
 
Example 4
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void init(@NonNull EglBase.Context sharedContext, @NonNull RendererCommon.RendererEvents rendererEvents, @NonNull int[] configAttributes, @NonNull RendererCommon.GlDrawer drawer) {
  ThreadUtils.checkIsOnMainThread();

  this.rendererEvents     = rendererEvents;
  this.rotatedFrameWidth  = 0;
  this.rotatedFrameHeight = 0;

  this.eglRenderer.init(sharedContext, this, configAttributes, drawer);
}
 
Example 5
Source File: VideoFileRenderer.java    From webrtc_android with MIT License 5 votes vote down vote up
public VideoFileRenderer(String outputFile, int outputFileWidth, int outputFileHeight,
                         final EglBase.Context sharedContext) throws IOException {
  if ((outputFileWidth % 2) == 1 || (outputFileHeight % 2) == 1) {
    throw new IllegalArgumentException("Does not support uneven width or height");
  }

  this.outputFileName = outputFile;
  this.outputFileWidth = outputFileWidth;
  this.outputFileHeight = outputFileHeight;

  outputFrameSize = outputFileWidth * outputFileHeight * 3 / 2;
  outputFrameBuffer = ByteBuffer.allocateDirect(outputFrameSize);

  videoOutFile = new FileOutputStream(outputFile);
  videoOutFile.write(
      ("YUV4MPEG2 C420 W" + outputFileWidth + " H" + outputFileHeight + " Ip F30:1 A1:1\n")
          .getBytes(Charset.forName("US-ASCII")));

  renderThread = new HandlerThread(TAG + "RenderThread");
  renderThread.start();
  renderThreadHandler = new Handler(renderThread.getLooper());

  fileThread = new HandlerThread(TAG + "FileThread");
  fileThread.start();
  fileThreadHandler = new Handler(fileThread.getLooper());

  ThreadUtils.invokeAtFrontUninterruptibly(renderThreadHandler, new Runnable() {
    @Override
    public void run() {
      eglBase = EglBase.create(sharedContext, EglBase.CONFIG_PIXEL_BUFFER);
      eglBase.createDummyPbufferSurface();
      eglBase.makeCurrent();
      yuvConverter = new YuvConverter();
    }
  });
}
 
Example 6
Source File: EglContextHacker.java    From UltraGpuImage with MIT License 5 votes vote down vote up
public static EGLContext getContextFromEglBase(EglBase eglBase) {
    EglBase.Context context = eglBase.getEglBaseContext();
    try {
        Field f = context.getClass().getDeclaredField("egl14Context");
        f.setAccessible(true);
        return (EGLContext) f.get(context);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 7
Source File: SurfaceTextureEglRenderer.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void init(@Nullable EglBase.Context sharedContext, @Nullable RendererCommon.RendererEvents rendererEvents, @NonNull int[] configAttributes, @NonNull RendererCommon.GlDrawer drawer) {
  ThreadUtils.checkIsOnMainThread();
  this.rendererEvents = rendererEvents;
  synchronized (this.layoutLock) {
    this.isFirstFrameRendered = false;
    this.rotatedFrameWidth    = 0;
    this.rotatedFrameHeight   = 0;
    this.frameRotation        = 0;
  }

  super.init(sharedContext, configAttributes, drawer);
}
 
Example 8
Source File: TextureViewRenderer.java    From VideoCRE with MIT License 5 votes vote down vote up
/**
 * Initialize this class, sharing resources with |sharedContext|. The custom |drawer| will be used
 * for drawing frames on the EGLSurface. This class is responsible for calling release() on
 * |drawer|. It is allowed to call init() to reinitialize the renderer after a previous
 * init()/release() cycle.
 */
public void init(final EglBase.Context sharedContext,
    RendererCommon.RendererEvents rendererEvents, final int[] configAttributes,
    RendererCommon.GlDrawer drawer) {
  ThreadUtils.checkIsOnMainThread();
  this.rendererEvents = rendererEvents;
  synchronized (layoutLock) {
    isFirstFrameRendered = false;
    rotatedFrameWidth = 0;
    rotatedFrameHeight = 0;
    frameRotation = 0;
  }
  eglRenderer.init(sharedContext, configAttributes, drawer);
}
 
Example 9
Source File: JingleRtpConnection.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
public EglBase.Context getEglBaseContext() {
    return webRTCWrapper.getEglBaseContext();
}
 
Example 10
Source File: WebRTCWrapper.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
EglBase.Context getEglBaseContext() {
    return this.eglBase.getEglBaseContext();
}
 
Example 11
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public EglBase.Context getRenderContext() {
  return rootEglBase.getEglBaseContext();
}
 
Example 12
Source File: JingleRtpConnection.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
public EglBase.Context getEglBaseContext() {
    return webRTCWrapper.getEglBaseContext();
}
 
Example 13
Source File: WebRTCWrapper.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
EglBase.Context getEglBaseContext() {
    return this.eglBase.getEglBaseContext();
}
 
Example 14
Source File: PeerConnectionClient.java    From sample-videoRTC with Apache License 2.0 4 votes vote down vote up
public EglBase.Context getRenderContext() {
  return rootEglBase.getEglBaseContext();
}
 
Example 15
Source File: MainActivity.java    From webrtc-android-tutorial with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EglBase.Context eglBaseContext = EglBase.create().getEglBaseContext();

        // create PeerConnectionFactory
        PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
                .builder(this)
                .createInitializationOptions());
        PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
        DefaultVideoEncoderFactory defaultVideoEncoderFactory =
                new DefaultVideoEncoderFactory(eglBaseContext, true, true);
        DefaultVideoDecoderFactory defaultVideoDecoderFactory =
                new DefaultVideoDecoderFactory(eglBaseContext);
        peerConnectionFactory = PeerConnectionFactory.builder()
                .setOptions(options)
                .setVideoEncoderFactory(defaultVideoEncoderFactory)
                .setVideoDecoderFactory(defaultVideoDecoderFactory)
                .createPeerConnectionFactory();

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

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


        remoteView = findViewById(R.id.remoteView);
        remoteView.setMirror(false);
        remoteView.init(eglBaseContext, null);


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

        mediaStream = peerConnectionFactory.createLocalMediaStream("mediaStream");
        mediaStream.addTrack(videoTrack);
        mediaStream.addTrack(audioTrack);

        SignalingClient.get().setCallback(this);
        call();
    }
 
Example 16
Source File: MainActivity.java    From webrtc-android-tutorial with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EglBase.Context eglBaseContext = EglBase.create().getEglBaseContext();

        // create PeerConnectionFactory
        PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
                .builder(this)
                .createInitializationOptions());
        PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
        DefaultVideoEncoderFactory defaultVideoEncoderFactory =
                new DefaultVideoEncoderFactory(eglBaseContext, true, true);
        DefaultVideoDecoderFactory defaultVideoDecoderFactory =
                new DefaultVideoDecoderFactory(eglBaseContext);
        peerConnectionFactory = PeerConnectionFactory.builder()
                .setOptions(options)
                .setVideoEncoderFactory(defaultVideoEncoderFactory)
                .setVideoDecoderFactory(defaultVideoDecoderFactory)
                .createPeerConnectionFactory();

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

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




        SurfaceTextureHelper remoteSurfaceTextureHelper = SurfaceTextureHelper.create("RemoteCaptureThread", eglBaseContext);
        // create VideoCapturer
        VideoCapturer remoteVideoCapturer = createCameraCapturer(false);
        VideoSource remoteVideoSource = peerConnectionFactory.createVideoSource(remoteVideoCapturer.isScreencast());
        remoteVideoCapturer.initialize(remoteSurfaceTextureHelper, getApplicationContext(), remoteVideoSource.getCapturerObserver());
        remoteVideoCapturer.startCapture(480, 640, 30);

        remoteView = findViewById(R.id.remoteView);
        remoteView.setMirror(false);
        remoteView.init(eglBaseContext, null);

        // create VideoTrack
        VideoTrack remoteVideoTrack = peerConnectionFactory.createVideoTrack("102", remoteVideoSource);
//        // display in remoteView
//        remoteVideoTrack.addSink(remoteView);



        mediaStreamLocal = peerConnectionFactory.createLocalMediaStream("mediaStreamLocal");
        mediaStreamLocal.addTrack(videoTrack);

        mediaStreamRemote = peerConnectionFactory.createLocalMediaStream("mediaStreamRemote");
        mediaStreamRemote.addTrack(remoteVideoTrack);

        call(mediaStreamLocal, mediaStreamRemote);
    }
 
Example 17
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public void init(@NonNull EglBase.Context sharedContext, @NonNull RendererCommon.RendererEvents rendererEvents) {
  this.init(sharedContext, rendererEvents, EglBase.CONFIG_PLAIN, new GlRectDrawer());
}
 
Example 18
Source File: SurfaceTextureEglRenderer.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void init(@Nullable EglBase.Context sharedContext, @NonNull int[] configAttributes, @NonNull RendererCommon.GlDrawer drawer) {
  this.init(sharedContext, null, configAttributes, drawer);
}
 
Example 19
Source File: ContextInitialization.java    From owt-client-android with Apache License 2.0 3 votes vote down vote up
/**
 * Set the EGL context used by hardware video encoder and decoder.
 *
 * @param localEglContext Must be the same as that used by VideoCapturerAndroid and any local
 * video
 * renderer.
 * @param remoteEglContext Must be the same as that used by any remote video renderer.
 * @return ContextInitialization
 */
public ContextInitialization setVideoHardwareAccelerationOptions(
        EglBase.Context localEglContext, EglBase.Context remoteEglContext) {
    RCHECK(!initialized);
    localContext = localEglContext;
    remoteContext = remoteEglContext;
    return this;
}
 
Example 20
Source File: TextureViewRenderer.java    From VideoCRE with MIT License 2 votes vote down vote up
/**
 * Initialize this class, sharing resources with |sharedContext|. It is allowed to call init() to
 * reinitialize the renderer after a previous init()/release() cycle.
 */
public void init(EglBase.Context sharedContext, RendererCommon.RendererEvents rendererEvents) {
  init(sharedContext, rendererEvents, EglBase.CONFIG_PLAIN, new GlRectDrawer());
}