Package org.webrtc
Class JavaI420Buffer
java.lang.Object
org.webrtc.JavaI420Buffer
- All Implemented Interfaces:
RefCounted,VideoFrame.Buffer,VideoFrame.I420Buffer
Implementation of VideoFrame.I420Buffer backed by Java direct byte buffers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteBufferprivate final ByteBufferprivate final ByteBufferprivate final intprivate final RefCountDelegateprivate final intprivate final intprivate final intprivate final int -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateJavaI420Buffer(int width, int height, ByteBuffer dataY, int strideY, ByteBuffer dataU, int strideU, ByteBuffer dataV, int strideV, Runnable releaseCallback) -
Method Summary
Modifier and TypeMethodDescriptionstatic JavaI420Bufferallocate(int width, int height) Allocates an empty I420Buffer suitable for an image of the given dimensions.private static voidcheckCapacity(ByteBuffer data, int width, int height, int stride) cropAndScale(int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) Crops a region defined by `cropx`, `cropY`, `cropWidth` and `cropHeight`.static VideoFrame.BuffercropAndScaleI420(VideoFrame.I420Buffer buffer, int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) getDataU()Returns a direct ByteBuffer containing U-plane data.getDataV()Returns a direct ByteBuffer containing V-plane data.getDataY()Returns a direct ByteBuffer containing Y-plane data.intintintintintgetWidth()Resolution of the buffer in pixels.private static voidnativeCropAndScaleI420(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU, int srcStrideU, ByteBuffer srcV, int srcStrideV, int cropX, int cropY, int cropWidth, int cropHeight, ByteBuffer dstY, int dstStrideY, ByteBuffer dstU, int dstStrideU, ByteBuffer dstV, int dstStrideV, int scaleWidth, int scaleHeight) voidrelease()Decreases ref count by one.voidretain()Increases ref count by one.toI420()Returns a memory-backed frame in I420 format.static JavaI420Bufferwrap(int width, int height, ByteBuffer dataY, int strideY, ByteBuffer dataU, int strideU, ByteBuffer dataV, int strideV, Runnable releaseCallback) Wraps existing ByteBuffers into JavaI420Buffer object without copying the contents.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.webrtc.VideoFrame.I420Buffer
getBufferType
-
Field Details
-
width
private final int width -
height
private final int height -
dataY
-
dataU
-
dataV
-
strideY
private final int strideY -
strideU
private final int strideU -
strideV
private final int strideV -
refCountDelegate
-
-
Constructor Details
-
JavaI420Buffer
private JavaI420Buffer(int width, int height, ByteBuffer dataY, int strideY, ByteBuffer dataU, int strideU, ByteBuffer dataV, int strideV, @Nullable Runnable releaseCallback)
-
-
Method Details
-
checkCapacity
-
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
Allocates an empty I420Buffer suitable for an image of the given dimensions. -
getWidth
public int getWidth()Description copied from interface:VideoFrame.BufferResolution of the buffer in pixels.- Specified by:
getWidthin interfaceVideoFrame.Buffer
-
getHeight
public int getHeight()- Specified by:
getHeightin interfaceVideoFrame.Buffer
-
getDataY
Description copied from interface:VideoFrame.I420BufferReturns 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:
getDataYin interfaceVideoFrame.I420Buffer
-
getDataU
Description copied from interface:VideoFrame.I420BufferReturns 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:
getDataUin interfaceVideoFrame.I420Buffer
-
getDataV
Description copied from interface:VideoFrame.I420BufferReturns 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:
getDataVin interfaceVideoFrame.I420Buffer
-
getStrideY
public int getStrideY()- Specified by:
getStrideYin interfaceVideoFrame.I420Buffer
-
getStrideU
public int getStrideU()- Specified by:
getStrideUin interfaceVideoFrame.I420Buffer
-
getStrideV
public int getStrideV()- Specified by:
getStrideVin interfaceVideoFrame.I420Buffer
-
toI420
Description copied from interface:VideoFrame.BufferReturns 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:
toI420in interfaceVideoFrame.Buffer
-
retain
public void retain()Description copied from interface:RefCountedIncreases ref count by one.- Specified by:
retainin interfaceRefCounted- Specified by:
retainin interfaceVideoFrame.Buffer
-
release
public void release()Description copied from interface:RefCountedDecreases ref count by one. When the ref count reaches zero, resources related to the object will be freed.- Specified by:
releasein interfaceRefCounted- Specified by:
releasein interfaceVideoFrame.Buffer
-
cropAndScale
public VideoFrame.Buffer cropAndScale(int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) Description copied from interface:VideoFrame.BufferCrops a region defined by `cropx`, `cropY`, `cropWidth` and `cropHeight`. Scales it to size `scaleWidth` x `scaleHeight`.- Specified by:
cropAndScalein interfaceVideoFrame.Buffer
-
cropAndScaleI420
public static VideoFrame.Buffer cropAndScaleI420(VideoFrame.I420Buffer buffer, int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) -
nativeCropAndScaleI420
private static void nativeCropAndScaleI420(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU, int srcStrideU, ByteBuffer srcV, int srcStrideV, int cropX, int cropY, int cropWidth, int cropHeight, ByteBuffer dstY, int dstStrideY, ByteBuffer dstU, int dstStrideU, ByteBuffer dstV, int dstStrideV, int scaleWidth, int scaleHeight)
-