org.webrtc.RendererCommon Java Examples

The following examples show how to use org.webrtc.RendererCommon. 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: CallFragment.java    From owt-client-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View mView = inflater.inflate(R.layout.fragment_call, container, false);
    publishBtn = mView.findViewById(R.id.publish_btn);
    publishBtn.setText(isPublishing ? R.string.unpublish : R.string.publish);
    publishBtn.setOnClickListener(this);
    backBtn = mView.findViewById(R.id.back_btn);
    backBtn.setOnClickListener(this);
    fullRenderer = mView.findViewById(R.id.full_renderer);
    fullRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    fullRenderer.setEnableHardwareScaler(true);
    smallRenderer = mView.findViewById(R.id.small_renderer);
    smallRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    smallRenderer.setOnTouchListener(touchListener);
    smallRenderer.setEnableHardwareScaler(true);
    smallRenderer.setZOrderMediaOverlay(true);

    mListener.onReady(smallRenderer, fullRenderer);
    return mView;
}
 
Example #2
Source File: UserTrackView.java    From QNRTC-Android with Apache License 2.0 6 votes vote down vote up
private void updateTrackInfoInLargeView(QNTrackInfo trackInfoDisplayInLargeView) {
    if (mTrackInfoDisplayInLargeView != null && mTrackInfoDisplayInLargeView == trackInfoDisplayInLargeView) {
        LogD(TAG, "skip updateTrackInfoInLargeView, same track");
        return;
    }
    mTrackInfoDisplayInLargeView = trackInfoDisplayInLargeView;
    if (mTrackInfoDisplayInLargeView != null) {
        if (DISPLAY_LARGE_VIDEO_TRACK) {
            mSurfaceViewLarge.setVisibility(View.VISIBLE);
            mQNRTCEngine.setRenderWindow(mTrackInfoDisplayInLargeView, mSurfaceViewLarge);
            if (TAG_SCREEN.equals(mTrackInfoDisplayInLargeView.getTag())) {
                mSurfaceViewLarge.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
            } else {
                mSurfaceViewLarge.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
            }
        } else {
            mSurfaceViewLarge.setVisibility(View.GONE);
            mVideoViewLargeParent.setBackgroundColor(getTargetColor(new Random().nextInt(6)));
        }
        mVideoViewLargeParent.setVisibility(View.VISIBLE);
    } else {
        mSurfaceViewLarge.setVisibility(View.GONE);
        mVideoViewLargeParent.setVisibility(View.GONE);
    }
}
 
Example #3
Source File: VOIPVideoActivity.java    From voip_android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void updateVideoView() {
    remoteRenderLayout.setPosition(REMOTE_X, REMOTE_Y, REMOTE_WIDTH, REMOTE_HEIGHT);
    remoteRender.setScalingType(scalingType);
    remoteRender.setMirror(false);

    if (iceConnected) {
        localRenderLayout.setPosition(
                LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED, LOCAL_WIDTH_CONNECTED, LOCAL_HEIGHT_CONNECTED);
        localRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    } else {
        localRenderLayout.setPosition(
                LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING, LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING);
        localRender.setScalingType(scalingType);
    }
    localRender.setMirror(true);

    localRender.requestLayout();
    remoteRender.requestLayout();
}
 
Example #4
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 #5
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 #6
Source File: TwilioRemotePreviewManager.java    From react-native-twilio-video-webrtc with MIT License 5 votes vote down vote up
@ReactProp(name = "scaleType")
public void setScaleType(TwilioRemotePreview view, @Nullable String scaleType) {

  if (scaleType.equals("fit")) {
    view.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
  } else {
    view.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
  }
}
 
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: PeerVideoActivity.java    From nubo-test with Apache License 2.0 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();

    Bundle extras = getIntent().getExtras();
    this.username = extras.getString(Constants.USER_NAME, "");
    Log.i(TAG, "username: " + username);

    EglBase rootEglBase = EglBase.create();
    masterView.init(rootEglBase.getEglBaseContext(), null);
    masterView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    localView.init(rootEglBase.getEglBaseContext(), null);
    localView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);

    NBMMediaConfiguration peerConnectionParameters = new NBMMediaConfiguration(
            NBMMediaConfiguration.NBMRendererType.OPENGLES,
            NBMMediaConfiguration.NBMAudioCodec.OPUS, 0,
            NBMMediaConfiguration.NBMVideoCodec.VP8, 0,
            new NBMMediaConfiguration.NBMVideoFormat(352, 288, PixelFormat.RGB_888, 20),
            NBMMediaConfiguration.NBMCameraPosition.FRONT);

    videoRequestUserMapping = new HashMap<>();

    nbmWebRTCPeer = new NBMWebRTCPeer(peerConnectionParameters, this, localView, this);
    nbmWebRTCPeer.registerMasterRenderer(masterView);
    Log.i(TAG, "Initializing nbmWebRTCPeer...");
    nbmWebRTCPeer.initialize();
    callState = CallState.PUBLISHING;
    mCallStatus.setText("Publishing...");
}
 
Example #9
Source File: VideoFragment.java    From owt-client-android with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View mView = inflater.inflate(R.layout.fragment_video, container, false);

    statsInView = mView.findViewById(R.id.stats_in);
    statsInView.setVisibility(View.GONE);
    statsOutView = mView.findViewById(R.id.stats_out);
    statsOutView.setVisibility(View.GONE);

    fullRenderer = mView.findViewById(R.id.full_renderer);
    smallRenderer = mView.findViewById(R.id.small_renderer);

    smallRenderer.init(((MainActivity) getActivity()).rootEglBase.getEglBaseContext(), null);
    smallRenderer.setMirror(true);
    smallRenderer.setOnTouchListener(touchListener);
    smallRenderer.setEnableHardwareScaler(true);
    smallRenderer.setZOrderMediaOverlay(true);

    fullRenderer.init(((MainActivity) getActivity()).rootEglBase.getEglBaseContext(), null);
    fullRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    fullRenderer.setEnableHardwareScaler(true);
    fullRenderer.setZOrderMediaOverlay(true);

    listener.onRenderer(smallRenderer, fullRenderer);
    clearStats(true);
    clearStats(false);
    return mView;
}
 
Example #10
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 #11
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void setScalingType(@NonNull RendererCommon.ScalingType scalingTypeMatchOrientation,
                           @NonNull RendererCommon.ScalingType scalingTypeMismatchOrientation)
{
  ThreadUtils.checkIsOnMainThread();

  videoLayoutMeasure.setScalingType(scalingTypeMatchOrientation, scalingTypeMismatchOrientation);

  requestLayout();
}
 
Example #12
Source File: TwilioVideoPreviewManager.java    From react-native-twilio-video-webrtc with MIT License 5 votes vote down vote up
@ReactProp(name = "scaleType")
public void setScaleType(TwilioVideoPreview view, @Nullable String scaleType) {
  if (scaleType.equals("fit")) {
    view.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
  } else {
    view.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
  }
}
 
Example #13
Source File: RNVideoViewGroup.java    From react-native-twilio-video-webrtc with MIT License 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int height = b - t;
    int width = r - l;
    if (height == 0 || width == 0) {
        l = t = r = b = 0;
    } else {
        int videoHeight;
        int videoWidth;
        synchronized (layoutSync) {
            videoHeight = this.videoHeight;
            videoWidth = this.videoWidth;
        }

        if (videoHeight == 0 || videoWidth == 0) {
            // These are Twilio defaults.
            videoHeight = 480;
            videoWidth = 640;
        }

        Point displaySize = RendererCommon.getDisplaySize(
                this.scalingType,
                videoWidth / (float) videoHeight,
                width,
                height
        );

        l = (width - displaySize.x) / 2;
        t = (height - displaySize.y) / 2;
        r = l + displaySize.x;
        b = t + displaySize.y;
    }
    surfaceViewRenderer.layout(l, t, r, b);
}
 
Example #14
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 #15
Source File: RTCGLVideoView.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public void updateRenderer(RendererSurface rendererSurface, RendererConfig config){
    boolean mainRenderer = RendererSurface.MAIN.equals(rendererSurface);
    VideoRenderer.Callbacks callbacks = mainRenderer ? mainRendererCallback
            :localRendererCallback;

    if (config.coordinates != null) {
        setViewCoordinates((mainRenderer ? remoteCoords : localCoords),
                config.coordinates);
    }
    setRendererMirror(config.mirror, rendererSurface);
    int[] viewCoordinates = mainRenderer ? remoteCoords : localCoords;
    VideoRendererGui.update(callbacks, viewCoordinates[0], viewCoordinates[1], viewCoordinates[2],
            viewCoordinates[3], RendererCommon.ScalingType.SCALE_ASPECT_FILL,
            (mainRenderer ? mainMirror : secondMirror));
}
 
Example #16
Source File: WebRtcCallView.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public void setLocalRenderer(@Nullable TextureViewRenderer surfaceViewRenderer) {
  if (localRenderer == surfaceViewRenderer) {
    return;
  }

  localRenderer = surfaceViewRenderer;

  if (surfaceViewRenderer == null) {
    setRenderer(largeLocalRenderContainer, null);
    setRenderer(smallLocalRenderContainer, null);
  } else {
    localRenderer.setMirror(cameraDirection == CameraState.Direction.FRONT);
    localRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
  }
}
 
Example #17
Source File: MatrixHelper.java    From VideoCRE with MIT License 4 votes vote down vote up
public void rotate(float[] matrix, float degree) {
    Matrix.setRotateM(mTemp, 0, degree, 0, 0, 1);
    RendererCommon.adjustOrigin(mTemp);
    Matrix.multiplyMM(mTemp, 16, mTemp, 0, matrix, 0);
    System.arraycopy(mTemp, 16, matrix, 0, 16);
}
 
Example #18
Source File: RNVideoViewGroup.java    From react-native-twilio-video-webrtc with MIT License 4 votes vote down vote up
public void setScalingType(RendererCommon.ScalingType scalingType) {
    this.scalingType = scalingType;
}
 
Example #19
Source File: ConversationCallFragment.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
protected void updateVideoView(QBRTCSurfaceView surfaceViewRenderer, boolean mirror) {
    updateVideoView(surfaceViewRenderer, mirror, RendererCommon.ScalingType.SCALE_ASPECT_FILL);
}
 
Example #20
Source File: ConversationCallFragment.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
protected void updateVideoView(QBRTCSurfaceView surfaceViewRenderer, boolean mirror, RendererCommon.ScalingType scalingType) {
    Log.i(TAG, "updateVideoView mirror:" + mirror + ", scalintType = " + scalingType);
    surfaceViewRenderer.setScalingType(scalingType);
    surfaceViewRenderer.setMirror(mirror);
    surfaceViewRenderer.requestLayout();
}
 
Example #21
Source File: RTCGLVideoView.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
private VideoRenderer.Callbacks initRenderer(boolean mirror, int[] viewCoordinates) {
    return VideoRendererGui.createGuiRenderer(viewCoordinates[0], viewCoordinates[1], viewCoordinates[2],
            viewCoordinates[3], RendererCommon.ScalingType.SCALE_ASPECT_FILL, mirror);

}
 
Example #22
Source File: TextureViewRenderer.java    From VideoCRE with MIT License 4 votes vote down vote up
public void setScalingType(RendererCommon.ScalingType scalingTypeMatchOrientation,
    RendererCommon.ScalingType scalingTypeMismatchOrientation) {
  ThreadUtils.checkIsOnMainThread();
  videoLayoutMeasure.setScalingType(scalingTypeMatchOrientation, scalingTypeMismatchOrientation);
  requestLayout();
}
 
Example #23
Source File: TextureViewRenderer.java    From VideoCRE with MIT License 4 votes vote down vote up
/**
 * Set how the video will fill the allowed layout area.
 */
public void setScalingType(RendererCommon.ScalingType scalingType) {
  ThreadUtils.checkIsOnMainThread();
  videoLayoutMeasure.setScalingType(scalingType);
  requestLayout();
}
 
Example #24
Source File: MatrixHelper.java    From VideoCRE with MIT License 4 votes vote down vote up
public MatrixHelper() {
    mFlipHorizontal = RendererCommon.horizontalFlipMatrix();
    mFlipVertical = RendererCommon.verticalFlipMatrix();
    mTemp = new float[32];
}
 
Example #25
Source File: CallActivity.java    From RTCStartupDemo with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_call);

    mLogcatView = findViewById(R.id.LogcatView);
    mStartCallBtn = findViewById(R.id.StartCallButton);
    mEndCallBtn = findViewById(R.id.EndCallButton);

    RTCSignalClient.getInstance().setSignalEventListener(mOnSignalEventListener);

    String serverAddr = getIntent().getStringExtra("ServerAddr");
    String roomName = getIntent().getStringExtra("RoomName");
    RTCSignalClient.getInstance().joinRoom(serverAddr, UUID.randomUUID().toString(), roomName);

    mRootEglBase = EglBase.create();

    mLocalSurfaceView = findViewById(R.id.LocalSurfaceView);
    mRemoteSurfaceView = findViewById(R.id.RemoteSurfaceView);

    mLocalSurfaceView.init(mRootEglBase.getEglBaseContext(), null);
    mLocalSurfaceView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    mLocalSurfaceView.setMirror(true);
    mLocalSurfaceView.setEnableHardwareScaler(false /* enabled */);

    mRemoteSurfaceView.init(mRootEglBase.getEglBaseContext(), null);
    mRemoteSurfaceView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
    mRemoteSurfaceView.setMirror(true);
    mRemoteSurfaceView.setEnableHardwareScaler(true /* enabled */);
    mRemoteSurfaceView.setZOrderMediaOverlay(true);

    ProxyVideoSink videoSink = new ProxyVideoSink();
    videoSink.setTarget(mLocalSurfaceView);

    mPeerConnectionFactory = createPeerConnectionFactory(this);

    // NOTE: this _must_ happen while PeerConnectionFactory is alive!
    Logging.enableLogToDebugOutput(Logging.Severity.LS_VERBOSE);

    mVideoCapturer = createVideoCapturer();

    mSurfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", mRootEglBase.getEglBaseContext());
    VideoSource videoSource = mPeerConnectionFactory.createVideoSource(false);
    mVideoCapturer.initialize(mSurfaceTextureHelper, getApplicationContext(), videoSource.getCapturerObserver());

    mVideoTrack = mPeerConnectionFactory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
    mVideoTrack.setEnabled(true);
    mVideoTrack.addSink(videoSink);

    AudioSource audioSource = mPeerConnectionFactory.createAudioSource(new MediaConstraints());
    mAudioTrack = mPeerConnectionFactory.createAudioTrack(AUDIO_TRACK_ID, audioSource);
    mAudioTrack.setEnabled(true);
}
 
Example #26
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public void addFrameListener(@NonNull EglRenderer.FrameListener listener, float scale, @NonNull RendererCommon.GlDrawer drawerParam) {
  eglRenderer.addFrameListener(listener, scale, drawerParam);
}
 
Example #27
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 #28
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 #29
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 3 votes vote down vote up
public void setScalingType(@NonNull RendererCommon.ScalingType scalingType) {
  ThreadUtils.checkIsOnMainThread();

  videoLayoutMeasure.setScalingType(scalingType);

  requestLayout();
}
 
Example #30
Source File: TextureViewRenderer.java    From VideoCRE with MIT License 2 votes vote down vote up
/**
 * Register a callback to be invoked when a new video frame has been received.
 *
 * @param listener The callback to be invoked. The callback will be invoked on the render thread.
 *                 It should be lightweight and must not call removeFrameListener.
 * @param scale    The scale of the Bitmap passed to the callback, or 0 if no Bitmap is
 *                 required.
 * @param drawer   Custom drawer to use for this frame listener.
 */
public void addFrameListener(
    EglRenderer.FrameListener listener, float scale, RendererCommon.GlDrawer drawerParam) {
  eglRenderer.addFrameListener(listener, scale, drawerParam);
}