Android: Annotate and generate JNI code for VideoFrame.java
This CL also merged native_handle_impl.cc and videoframe_jni.cc to keep all JNI code for the same Java class in the same file, and also renames this file to jni/videoframe.cc. The classes AndroidVideoBufferFactory and JavaVideoFrameFactory are now unnecessary since we cache everything and can be simplified to global static functions instead. Bug: webrtc:8278 Change-Id: I03d7b0bbde64cfb407cd6210478ddf9d5599cd8c Reviewed-on: https://webrtc-review.googlesource.com/22923 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20677}
This commit is contained in:
committed by
Commit Bot
parent
651707bdf0
commit
c2ac3c663f
@ -30,22 +30,22 @@ public class VideoFrame {
|
||||
/**
|
||||
* Resolution of the buffer in pixels.
|
||||
*/
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
@CalledByNative("Buffer") int getWidth();
|
||||
@CalledByNative("Buffer") int getHeight();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
I420Buffer toI420();
|
||||
@CalledByNative("Buffer") I420Buffer toI420();
|
||||
|
||||
/**
|
||||
* Reference counting is needed since a video buffer can be shared between multiple VideoSinks,
|
||||
* and the buffer needs to be returned to the VideoSource as soon as all references are gone.
|
||||
*/
|
||||
void retain();
|
||||
void release();
|
||||
@CalledByNative("Buffer") void retain();
|
||||
@CalledByNative("Buffer") void release();
|
||||
|
||||
/**
|
||||
* Crops a region defined by |cropx|, |cropY|, |cropWidth| and |cropHeight|. Scales it to size
|
||||
@ -65,25 +65,25 @@ public class VideoFrame {
|
||||
* be 0. Callers may mutate the ByteBuffer (eg. through relative-read operations), so
|
||||
* implementations must return a new ByteBuffer or slice for each call.
|
||||
*/
|
||||
ByteBuffer getDataY();
|
||||
@CalledByNative("I420Buffer") ByteBuffer getDataY();
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
ByteBuffer getDataU();
|
||||
@CalledByNative("I420Buffer") ByteBuffer getDataU();
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
ByteBuffer getDataV();
|
||||
@CalledByNative("I420Buffer") ByteBuffer getDataV();
|
||||
|
||||
int getStrideY();
|
||||
int getStrideU();
|
||||
int getStrideV();
|
||||
@CalledByNative("I420Buffer") int getStrideY();
|
||||
@CalledByNative("I420Buffer") int getStrideU();
|
||||
@CalledByNative("I420Buffer") int getStrideV();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,6 +132,7 @@ public class VideoFrame {
|
||||
this.timestampNs = timestampNs;
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
public Buffer getBuffer() {
|
||||
return buffer;
|
||||
}
|
||||
@ -139,6 +140,7 @@ public class VideoFrame {
|
||||
/**
|
||||
* Rotation of the frame in degrees.
|
||||
*/
|
||||
@CalledByNative
|
||||
public int getRotation() {
|
||||
return rotation;
|
||||
}
|
||||
@ -146,6 +148,7 @@ public class VideoFrame {
|
||||
/**
|
||||
* Timestamp of the frame in nano seconds.
|
||||
*/
|
||||
@CalledByNative
|
||||
public long getTimestampNs() {
|
||||
return timestampNs;
|
||||
}
|
||||
@ -194,7 +197,7 @@ public class VideoFrame {
|
||||
}
|
||||
|
||||
JavaI420Buffer newBuffer = JavaI420Buffer.allocate(scaleWidth, scaleHeight);
|
||||
nativeCropAndScaleI420(buffer.getDataY(), buffer.getStrideY(), buffer.getDataU(),
|
||||
cropAndScaleI420Native(buffer.getDataY(), buffer.getStrideY(), buffer.getDataU(),
|
||||
buffer.getStrideU(), buffer.getDataV(), buffer.getStrideV(), cropX, cropY, cropWidth,
|
||||
cropHeight, newBuffer.getDataY(), newBuffer.getStrideY(), newBuffer.getDataU(),
|
||||
newBuffer.getStrideU(), newBuffer.getDataV(), newBuffer.getStrideV(), scaleWidth,
|
||||
@ -202,7 +205,13 @@ public class VideoFrame {
|
||||
return newBuffer;
|
||||
}
|
||||
|
||||
private static native void nativeCropAndScaleI420(ByteBuffer srcY, int srcStrideY,
|
||||
// TODO(bugs.webrtc.org/8278): Add a way to generate JNI code for constructors directly.
|
||||
@CalledByNative
|
||||
static VideoFrame create(Buffer buffer, int rotation, long timestampNs) {
|
||||
return new VideoFrame(buffer, rotation, timestampNs);
|
||||
}
|
||||
|
||||
private static native void cropAndScaleI420Native(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);
|
||||
|
||||
Reference in New Issue
Block a user