More systematic null checks before calling native methods
None of these native methods perform null checks. Some of the Java delegates were doing some null checks, but calling others with null parameters would just result in native crashes that often lack context. These more systematic checks will make debugging easier. Bug: b/282038690 Change-Id: I3363abeede84c1bd93da397fe87c3d638a607107 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/306961 Reviewed-by: Linus Nilsson <lnilsson@webrtc.org> Commit-Queue: Xavier Lepaul <xalep@webrtc.org> Reviewed-by: Ranveer Aggarwal <ranvr@webrtc.org> Cr-Commit-Position: refs/heads/main@{#40175}
This commit is contained in:
parent
a3e9c0ae5a
commit
c73ea4fc57
@ -115,6 +115,10 @@ public class YuvHelper {
|
|||||||
public static void I420Rotate(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU, int srcStrideU,
|
public static void I420Rotate(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU, int srcStrideU,
|
||||||
ByteBuffer srcV, int srcStrideV, ByteBuffer dst, int srcWidth, int srcHeight,
|
ByteBuffer srcV, int srcStrideV, ByteBuffer dst, int srcWidth, int srcHeight,
|
||||||
int rotationMode) {
|
int rotationMode) {
|
||||||
|
checkNotNull(srcY, "srcY");
|
||||||
|
checkNotNull(srcU, "srcU");
|
||||||
|
checkNotNull(srcV, "srcV");
|
||||||
|
checkNotNull(dst, "dst");
|
||||||
final int dstWidth = rotationMode % 180 == 0 ? srcWidth : srcHeight;
|
final int dstWidth = rotationMode % 180 == 0 ? srcWidth : srcHeight;
|
||||||
final int dstHeight = rotationMode % 180 == 0 ? srcHeight : srcWidth;
|
final int dstHeight = rotationMode % 180 == 0 ? srcHeight : srcWidth;
|
||||||
|
|
||||||
@ -145,14 +149,16 @@ public class YuvHelper {
|
|||||||
/** Helper method for copying a single colour plane. */
|
/** Helper method for copying a single colour plane. */
|
||||||
public static void copyPlane(
|
public static void copyPlane(
|
||||||
ByteBuffer src, int srcStride, ByteBuffer dst, int dstStride, int width, int height) {
|
ByteBuffer src, int srcStride, ByteBuffer dst, int dstStride, int width, int height) {
|
||||||
nativeCopyPlane(src, srcStride, dst, dstStride, width, height);
|
nativeCopyPlane(
|
||||||
|
checkNotNull(src, "src"), srcStride, checkNotNull(dst, "dst"), dstStride, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Converts ABGR little endian (rgba in memory) to I420. */
|
/** Converts ABGR little endian (rgba in memory) to I420. */
|
||||||
public static void ABGRToI420(ByteBuffer src, int srcStride, ByteBuffer dstY, int dstStrideY,
|
public static void ABGRToI420(ByteBuffer src, int srcStride, ByteBuffer dstY, int dstStrideY,
|
||||||
ByteBuffer dstU, int dstStrideU, ByteBuffer dstV, int dstStrideV, int width, int height) {
|
ByteBuffer dstU, int dstStrideU, ByteBuffer dstV, int dstStrideV, int width, int height) {
|
||||||
nativeABGRToI420(
|
nativeABGRToI420(checkNotNull(src, "src"), srcStride, checkNotNull(dstY, "dstY"), dstStrideY,
|
||||||
src, srcStride, dstY, dstStrideY, dstU, dstStrideU, dstV, dstStrideV, width, height);
|
checkNotNull(dstU, "dstU"), dstStrideU, checkNotNull(dstV, "dstV"), dstStrideV, width,
|
||||||
|
height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,9 +169,14 @@ public class YuvHelper {
|
|||||||
public static void I420Copy(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU, int srcStrideU,
|
public static void I420Copy(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU, int srcStrideU,
|
||||||
ByteBuffer srcV, int srcStrideV, ByteBuffer dstY, int dstStrideY, ByteBuffer dstU,
|
ByteBuffer srcV, int srcStrideV, ByteBuffer dstY, int dstStrideY, ByteBuffer dstU,
|
||||||
int dstStrideU, ByteBuffer dstV, int dstStrideV, int width, int height) {
|
int dstStrideU, ByteBuffer dstV, int dstStrideV, int width, int height) {
|
||||||
if (srcY == null || srcU == null || srcV == null || dstY == null || dstU == null || dstV == null
|
checkNotNull(srcY, "srcY");
|
||||||
|| width <= 0 || height <= 0) {
|
checkNotNull(srcU, "srcU");
|
||||||
throw new IllegalArgumentException("Invalid I420Copy input arguments");
|
checkNotNull(srcV, "srcV");
|
||||||
|
checkNotNull(dstY, "dstY");
|
||||||
|
checkNotNull(dstU, "dstU");
|
||||||
|
checkNotNull(dstV, "dstV");
|
||||||
|
if (width <= 0 || height <= 0) {
|
||||||
|
throw new IllegalArgumentException("I420Copy: width and height should not be negative");
|
||||||
}
|
}
|
||||||
nativeI420Copy(srcY, srcStrideY, srcU, srcStrideU, srcV, srcStrideV, dstY, dstStrideY, dstU,
|
nativeI420Copy(srcY, srcStrideY, srcU, srcStrideU, srcV, srcStrideV, dstY, dstStrideY, dstU,
|
||||||
dstStrideU, dstV, dstStrideV, width, height);
|
dstStrideU, dstV, dstStrideV, width, height);
|
||||||
@ -174,9 +185,13 @@ public class YuvHelper {
|
|||||||
public static void I420ToNV12(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU, int srcStrideU,
|
public static void I420ToNV12(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU, int srcStrideU,
|
||||||
ByteBuffer srcV, int srcStrideV, ByteBuffer dstY, int dstStrideY, ByteBuffer dstUV,
|
ByteBuffer srcV, int srcStrideV, ByteBuffer dstY, int dstStrideY, ByteBuffer dstUV,
|
||||||
int dstStrideUV, int width, int height) {
|
int dstStrideUV, int width, int height) {
|
||||||
if (srcY == null || srcU == null || srcV == null || dstY == null || dstUV == null || width <= 0
|
checkNotNull(srcY, "srcY");
|
||||||
|| height <= 0) {
|
checkNotNull(srcU, "srcU");
|
||||||
throw new IllegalArgumentException("Invalid I420ToNV12 input arguments");
|
checkNotNull(srcV, "srcV");
|
||||||
|
checkNotNull(dstY, "dstY");
|
||||||
|
checkNotNull(dstUV, "dstUV");
|
||||||
|
if (width <= 0 || height <= 0) {
|
||||||
|
throw new IllegalArgumentException("I420ToNV12: width and height should not be negative");
|
||||||
}
|
}
|
||||||
nativeI420ToNV12(srcY, srcStrideY, srcU, srcStrideU, srcV, srcStrideV, dstY, dstStrideY, dstUV,
|
nativeI420ToNV12(srcY, srcStrideY, srcU, srcStrideU, srcV, srcStrideV, dstY, dstStrideY, dstUV,
|
||||||
dstStrideUV, width, height);
|
dstStrideUV, width, height);
|
||||||
@ -186,10 +201,23 @@ public class YuvHelper {
|
|||||||
ByteBuffer srcV, int srcStrideV, ByteBuffer dstY, int dstStrideY, ByteBuffer dstU,
|
ByteBuffer srcV, int srcStrideV, ByteBuffer dstY, int dstStrideY, ByteBuffer dstU,
|
||||||
int dstStrideU, ByteBuffer dstV, int dstStrideV, int srcWidth, int srcHeight,
|
int dstStrideU, ByteBuffer dstV, int dstStrideV, int srcWidth, int srcHeight,
|
||||||
int rotationMode) {
|
int rotationMode) {
|
||||||
|
checkNotNull(srcY, "srcY");
|
||||||
|
checkNotNull(srcU, "srcU");
|
||||||
|
checkNotNull(srcV, "srcV");
|
||||||
|
checkNotNull(dstY, "dstY");
|
||||||
|
checkNotNull(dstU, "dstU");
|
||||||
|
checkNotNull(dstV, "dstV");
|
||||||
nativeI420Rotate(srcY, srcStrideY, srcU, srcStrideU, srcV, srcStrideV, dstY, dstStrideY, dstU,
|
nativeI420Rotate(srcY, srcStrideY, srcU, srcStrideU, srcV, srcStrideV, dstY, dstStrideY, dstU,
|
||||||
dstStrideU, dstV, dstStrideV, srcWidth, srcHeight, rotationMode);
|
dstStrideU, dstV, dstStrideV, srcWidth, srcHeight, rotationMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> T checkNotNull(T obj, String description) {
|
||||||
|
if (obj == null) {
|
||||||
|
throw new NullPointerException(description + " should not be null");
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
private static native void nativeCopyPlane(
|
private static native void nativeCopyPlane(
|
||||||
ByteBuffer src, int srcStride, ByteBuffer dst, int dstStride, int width, int height);
|
ByteBuffer src, int srcStride, ByteBuffer dst, int dstStride, int width, int height);
|
||||||
private static native void nativeI420Copy(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU,
|
private static native void nativeI420Copy(ByteBuffer srcY, int srcStrideY, ByteBuffer srcU,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user