Package tvi.webrtc

Class JavaI420Buffer

java.lang.Object
tvi.webrtc.JavaI420Buffer
All Implemented Interfaces:
RefCounted, VideoFrame.Buffer, VideoFrame.I420Buffer

public class JavaI420Buffer extends Object implements VideoFrame.I420Buffer
Implementation of VideoFrame.I420Buffer backed by Java direct byte buffers.
  • Method Details

    • wrap

      public static JavaI420Buffer wrap(int width, int height, ByteBuffer dataY, int strideY, ByteBuffer dataU, int strideU, ByteBuffer dataV, int strideV, @Nullable Runnable releaseCallback)
      Wraps existing ByteBuffers into JavaI420Buffer object without copying the contents.
    • allocate

      public static JavaI420Buffer allocate(int width, int height)
      Allocates an empty I420Buffer suitable for an image of the given dimensions.
    • getWidth

      public int getWidth()
      Description copied from interface: VideoFrame.Buffer
      Resolution of the buffer in pixels.
      Specified by:
      getWidth in interface VideoFrame.Buffer
    • getHeight

      public int getHeight()
      Specified by:
      getHeight in interface VideoFrame.Buffer
    • getDataY

      public ByteBuffer getDataY()
      Description copied from interface: VideoFrame.I420Buffer
      Returns a direct ByteBuffer containing Y-plane data. The buffer capacity is at least getStrideY() * getHeight() bytes. The position of the returned buffer is ignored and must be 0. Callers may mutate the ByteBuffer (eg. through relative-read operations), so implementations must return a new ByteBuffer or slice for each call.
      Specified by:
      getDataY in interface VideoFrame.I420Buffer
    • getDataU

      public ByteBuffer getDataU()
      Description copied from interface: VideoFrame.I420Buffer
      Returns a direct ByteBuffer containing U-plane data. The buffer capacity is at least getStrideU() * ((getHeight() + 1) / 2) bytes. The position of the returned buffer is ignored and must be 0. Callers may mutate the ByteBuffer (eg. through relative-read operations), so implementations must return a new ByteBuffer or slice for each call.
      Specified by:
      getDataU in interface VideoFrame.I420Buffer
    • getDataV

      public ByteBuffer getDataV()
      Description copied from interface: VideoFrame.I420Buffer
      Returns a direct ByteBuffer containing V-plane data. The buffer capacity is at least getStrideV() * ((getHeight() + 1) / 2) bytes. The position of the returned buffer is ignored and must be 0. Callers may mutate the ByteBuffer (eg. through relative-read operations), so implementations must return a new ByteBuffer or slice for each call.
      Specified by:
      getDataV in interface VideoFrame.I420Buffer
    • getStrideY

      public int getStrideY()
      Specified by:
      getStrideY in interface VideoFrame.I420Buffer
    • getStrideU

      public int getStrideU()
      Specified by:
      getStrideU in interface VideoFrame.I420Buffer
    • getStrideV

      public int getStrideV()
      Specified by:
      getStrideV in interface VideoFrame.I420Buffer
    • toI420

      public VideoFrame.I420Buffer toI420()
      Description copied from interface: VideoFrame.Buffer
      Returns a memory-backed frame in I420 format. If the pixel data is in another format, a conversion will take place. All implementations must provide a fallback to I420 for compatibility with e.g. the internal WebRTC software encoders.

      Conversion may fail, for example if reading the pixel data from a texture fails. If the conversion fails, null is returned.

      Specified by:
      toI420 in interface VideoFrame.Buffer
    • retain

      public void retain()
      Description copied from interface: RefCounted
      Increases ref count by one.
      Specified by:
      retain in interface RefCounted
      Specified by:
      retain in interface VideoFrame.Buffer
    • release

      public void release()
      Description copied from interface: RefCounted
      Decreases ref count by one. When the ref count reaches zero, resources related to the object will be freed.
      Specified by:
      release in interface RefCounted
      Specified by:
      release in interface VideoFrame.Buffer
    • cropAndScale

      public VideoFrame.Buffer cropAndScale(int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight)
      Description copied from interface: VideoFrame.Buffer
      Crops a region defined by `cropx`, `cropY`, `cropWidth` and `cropHeight`. Scales it to size `scaleWidth` x `scaleHeight`.
      Specified by:
      cropAndScale in interface VideoFrame.Buffer
    • cropAndScaleI420

      public static VideoFrame.Buffer cropAndScaleI420(VideoFrame.I420Buffer buffer, int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight)