org.webrtc.VideoFrame Java Examples

The following examples show how to use org.webrtc.VideoFrame. 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: SurfaceTextureEglRenderer.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void updateFrameDimensionsAndReportEvents(VideoFrame frame) {
  synchronized(this.layoutLock) {
    if (!this.isRenderingPaused) {
      if (!this.isFirstFrameRendered) {
        this.isFirstFrameRendered = true;
        Log.d(TAG, "Reporting first rendered frame.");
        if (this.rendererEvents != null) {
          this.rendererEvents.onFirstFrameRendered();
        }
      }

      if (this.rotatedFrameWidth != frame.getRotatedWidth() || this.rotatedFrameHeight != frame.getRotatedHeight() || this.frameRotation != frame.getRotation()) {
        Log.d(TAG, "Reporting frame resolution changed to " + frame.getBuffer().getWidth() + "x" + frame.getBuffer().getHeight() + " with rotation " + frame.getRotation());
        if (this.rendererEvents != null) {
          this.rendererEvents.onFrameResolutionChanged(frame.getBuffer().getWidth(), frame.getBuffer().getHeight(), frame.getRotation());
        }

        this.rotatedFrameWidth  = frame.getRotatedWidth();
        this.rotatedFrameHeight = frame.getRotatedHeight();
        this.frameRotation      = frame.getRotation();
      }
    }
  }
}
 
Example #2
Source File: WebRTC.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
private void addVideoTrack(MediaStream mediaStream) {

        if (callTYpe == ProtoSignalingOffer.SignalingOffer.Type.VIDEO_CALLING) {
            videoCapturer = createCameraCapturer(new Camera1Enumerator(false));
            videoSource = peerConnectionFactoryInstance().createVideoSource(videoCapturer);
            videoCapturer.startCapture(VIDEO_RESOLUTION_WIDTH, VIDEO_RESOLUTION_HEIGHT, FPS);
            videoTrackFromCamera = peerConnectionFactoryInstance().createVideoTrack(VIDEO_TRACK_ID, videoSource);
            videoTrackFromCamera.setEnabled(true);

            videoTrackFromCamera.addSink(new VideoSink() {
                @Override
                public void onFrame(VideoFrame videoFrame) {
                    if (G.onVideoCallFrame != null) {
                        G.onVideoCallFrame.onPeerFrame(videoFrame);
                    }
                }
            });

            mediaStream.addTrack(videoTrackFromCamera);
        }
    }
 
Example #3
Source File: PeerConnectionObserver.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onAddStream(MediaStream stream) {
    for (AudioTrack audioTrack : stream.audioTracks) {
        audioTrack.setEnabled(true);
    }

    if (stream.videoTracks != null && stream.videoTracks.size() == 1) {
        VideoTrack videoTrack = stream.videoTracks.get(0);
        videoTrack.setEnabled(true);

        videoTrack.addSink(new VideoSink() {
            @Override
            public void onFrame(VideoFrame videoFrame) {

                if (G.onVideoCallFrame != null) {
                    G.onVideoCallFrame.onRemoteFrame(videoFrame);
                }
            }
        });

    }


}
 
Example #4
Source File: NativeCapturerObserver.java    From webrtc_android with MIT License 6 votes vote down vote up
@Override
public void onFrameCaptured(VideoFrame frame) {
  final NativeAndroidVideoTrackSource.FrameAdaptationParameters parameters =
      nativeAndroidVideoTrackSource.adaptFrame(frame);
  if (parameters == null) {
    // Drop frame.
    return;
  }

  final VideoFrame.Buffer adaptedBuffer =
      frame.getBuffer().cropAndScale(parameters.cropX, parameters.cropY, parameters.cropWidth,
          parameters.cropHeight, parameters.scaleWidth, parameters.scaleHeight);
  nativeAndroidVideoTrackSource.onFrameCaptured(
      new VideoFrame(adaptedBuffer, frame.getRotation(), parameters.timestampNs));
  adaptedBuffer.release();
}
 
Example #5
Source File: ProxyVideoSink.java    From webrtc_android with MIT License 5 votes vote down vote up
@Override
synchronized public void onFrame(VideoFrame frame) {
    if (target == null) {
        Logging.d(TAG, "Dropping frame in proxy because target is null.");
        return;
    }
    target.onFrame(frame);
}
 
Example #6
Source File: CallActivity.java    From RTCStartupDemo with GNU General Public License v3.0 5 votes vote down vote up
@Override
synchronized public void onFrame(VideoFrame frame) {
    if (mTarget == null) {
        Log.d(TAG, "Dropping frame in proxy because target is null.");
        return;
    }
    mTarget.onFrame(frame);
}
 
Example #7
Source File: CallActivity.java    From sample-videoRTC with Apache License 2.0 5 votes vote down vote up
@Override
synchronized public void onFrame(VideoFrame frame) {
    if (target == null) {
        Logging.d(TAG, "Dropping frame in proxy because target is null.");
        return;
    }

    target.onFrame(frame);
}
 
Example #8
Source File: FakeRenderer.java    From owt-client-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onFrame(VideoFrame videoFrame) {
    synchronized (lock) {
        ++framesRendered;
        width = videoFrame.getRotatedWidth();
        height = videoFrame.getRotatedHeight();
    }
    videoFrame.release();
}
 
Example #9
Source File: VideoFileRenderer.java    From webrtc_android with MIT License 4 votes vote down vote up
private void renderFrameOnRenderThread(VideoFrame frame) {
  final VideoFrame.Buffer buffer = frame.getBuffer();

  // If the frame is rotated, it will be applied after cropAndScale. Therefore, if the frame is
  // rotated by 90 degrees, swap width and height.
  final int targetWidth = frame.getRotation() % 180 == 0 ? outputFileWidth : outputFileHeight;
  final int targetHeight = frame.getRotation() % 180 == 0 ? outputFileHeight : outputFileWidth;

  final float frameAspectRatio = (float) buffer.getWidth() / (float) buffer.getHeight();
  final float fileAspectRatio = (float) targetWidth / (float) targetHeight;

  // Calculate cropping to equalize the aspect ratio.
  int cropWidth = buffer.getWidth();
  int cropHeight = buffer.getHeight();
  if (fileAspectRatio > frameAspectRatio) {
    cropHeight = (int) (cropHeight * (frameAspectRatio / fileAspectRatio));
  } else {
    cropWidth = (int) (cropWidth * (fileAspectRatio / frameAspectRatio));
  }

  final int cropX = (buffer.getWidth() - cropWidth) / 2;
  final int cropY = (buffer.getHeight() - cropHeight) / 2;

  final VideoFrame.Buffer scaledBuffer =
      buffer.cropAndScale(cropX, cropY, cropWidth, cropHeight, targetWidth, targetHeight);
  frame.release();

  final VideoFrame.I420Buffer i420 = scaledBuffer.toI420();
  scaledBuffer.release();

  fileThreadHandler.post(() -> {
    YuvHelper.I420Rotate(i420.getDataY(), i420.getStrideY(), i420.getDataU(), i420.getStrideU(),
        i420.getDataV(), i420.getStrideV(), outputFrameBuffer, i420.getWidth(), i420.getHeight(),
        frame.getRotation());
    i420.release();

    try {
      videoOutFile.write("FRAME\n".getBytes(Charset.forName("US-ASCII")));
      videoOutFile.write(
          outputFrameBuffer.array(), outputFrameBuffer.arrayOffset(), outputFrameSize);
    } catch (IOException e) {
      throw new RuntimeException("Error writing video to disk", e);
    }
    frameCount++;
  });
}
 
Example #10
Source File: VideoFileRenderer.java    From webrtc_android with MIT License 4 votes vote down vote up
@Override
public void onFrame(VideoFrame frame) {
  frame.retain();
  renderThreadHandler.post(() -> renderFrameOnRenderThread(frame));
}
 
Example #11
Source File: VideoSink.java    From VideoCRE with MIT License 4 votes vote down vote up
@Override
public void onFrameCaptured(final VideoFrame frame) {
}
 
Example #12
Source File: ActivityCall.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onRemoteFrame(VideoFrame videoFrame) {
    activityCallBinding.fcrSurfaceRemote.onFrame(videoFrame);
}
 
Example #13
Source File: ActivityCall.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onPeerFrame(VideoFrame videoFrame) {
    activityCallBinding.fcrSurfacePeer.onFrame(videoFrame);
}
 
Example #14
Source File: TextureViewRenderer.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onFrame(VideoFrame videoFrame) {
  eglRenderer.onFrame(videoFrame);
}
 
Example #15
Source File: SurfaceTextureEglRenderer.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onFrame(@NonNull VideoFrame frame) {
  this.updateFrameDimensionsAndReportEvents(frame);
  super.onFrame(frame);
}
 
Example #16
Source File: OnVideoCallFrame.java    From iGap-Android with GNU Affero General Public License v3.0 votes vote down vote up
void onRemoteFrame(VideoFrame videoFrame); 
Example #17
Source File: OnVideoCallFrame.java    From iGap-Android with GNU Affero General Public License v3.0 votes vote down vote up
void onPeerFrame(VideoFrame videoFrame);