Index: webrtc/sdk/android/api/org/webrtc/VideoFrame.java |
diff --git a/webrtc/sdk/android/api/org/webrtc/VideoFrame.java b/webrtc/sdk/android/api/org/webrtc/VideoFrame.java |
index 3da772dd9b9c55eb3ca6863ac31d52eb3a29ef23..7e9b86bf9c21678c9decb9a7e176f1b98d1858d9 100644 |
--- a/webrtc/sdk/android/api/org/webrtc/VideoFrame.java |
+++ b/webrtc/sdk/android/api/org/webrtc/VideoFrame.java |
@@ -44,6 +44,13 @@ public class VideoFrame { |
*/ |
void retain(); |
void release(); |
+ |
+ /** |
+ * Crops a region defined by |cropx|, |cropY|, |cropWidth| and |cropHeight|. Scales it to size |
+ * |scaleWidth| x |scaleHeight|. |
+ */ |
+ Buffer cropAndScale( |
+ int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight); |
} |
/** |
@@ -67,24 +74,26 @@ public class VideoFrame { |
Type getType(); |
int getTextureId(); |
+ |
+ /** |
+ * Retrieve the transform matrix associated with the frame. This transform matrix maps 2D |
+ * homogeneous coordinates of the form (s, t, 1) with s and t in the inclusive range [0, 1] to |
+ * the coordinate that should be used to sample that location from the buffer. |
+ */ |
+ public Matrix getTransformMatrix(); |
} |
private final Buffer buffer; |
private final int rotation; |
private final long timestampNs; |
- private final Matrix transformMatrix; |
- public VideoFrame(Buffer buffer, int rotation, long timestampNs, Matrix transformMatrix) { |
+ public VideoFrame(Buffer buffer, int rotation, long timestampNs) { |
if (buffer == null) { |
throw new IllegalArgumentException("buffer not allowed to be null"); |
} |
- if (transformMatrix == null) { |
- throw new IllegalArgumentException("transformMatrix not allowed to be null"); |
- } |
this.buffer = buffer; |
this.rotation = rotation; |
this.timestampNs = timestampNs; |
- this.transformMatrix = transformMatrix; |
} |
public Buffer getBuffer() { |
@@ -105,26 +114,6 @@ public class VideoFrame { |
return timestampNs; |
} |
- /** |
- * Retrieve the transform matrix associated with the frame. This transform matrix maps 2D |
- * homogeneous coordinates of the form (s, t, 1) with s and t in the inclusive range [0, 1] to the |
- * coordinate that should be used to sample that location from the buffer. |
- */ |
- public Matrix getTransformMatrix() { |
- return transformMatrix; |
- } |
- |
- /** |
- * Resolution of the frame in pixels. |
- */ |
- public int getWidth() { |
- return buffer.getWidth(); |
- } |
- |
- public int getHeight() { |
- return buffer.getHeight(); |
- } |
- |
/** |
* Reference counting of the underlying buffer. |
*/ |
@@ -135,4 +124,20 @@ public class VideoFrame { |
public void release() { |
buffer.release(); |
} |
+ |
+ public static VideoFrame.Buffer cropAndScaleI420(I420Buffer buffer, int cropX, int cropY, |
magjed_webrtc
2017/07/27 14:02:29
Maybe we should implement an optimized path for pu
sakal
2017/07/28 08:01:36
Done.
|
+ int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) { |
+ I420BufferImpl newBuffer = I420BufferImpl.allocate(scaleWidth, scaleHeight); |
+ nativeCropAndScaleI420(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, |
+ scaleHeight); |
+ return newBuffer; |
+ } |
+ |
+ private static native 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); |
} |