diff --git a/sdk/android/api/org/webrtc/VideoFrame.java b/sdk/android/api/org/webrtc/VideoFrame.java index 6a92cc9b23..a13112105e 100644 --- a/sdk/android/api/org/webrtc/VideoFrame.java +++ b/sdk/android/api/org/webrtc/VideoFrame.java @@ -59,17 +59,20 @@ public class VideoFrame { public interface I420Buffer extends Buffer { /** * Returns a direct ByteBuffer containing Y-plane data. The buffer size is at least getStrideY() - * * getHeight() bytes. + * * getHeight() bytes. Callers may mutate the ByteBuffer (eg. through relative-read + * operations), so implementations must return a new ByteBuffer or slice for each call. */ ByteBuffer getDataY(); /** * Returns a direct ByteBuffer containing U-plane data. The buffer size is at least getStrideU() - * * ((getHeight() + 1) / 2) bytes. + * * ((getHeight() + 1) / 2) bytes. Callers may mutate the ByteBuffer (eg. through relative-read + * operations), so implementations must return a new ByteBuffer or slice for each call. */ ByteBuffer getDataU(); /** * Returns a direct ByteBuffer containing V-plane data. The buffer size is at least getStrideV() - * * ((getHeight() + 1) / 2) bytes. + * * ((getHeight() + 1) / 2) bytes. Callers may mutate the ByteBuffer (eg. through relative-read + * operations), so implementations must return a new ByteBuffer or slice for each call. */ ByteBuffer getDataV(); diff --git a/sdk/android/src/java/org/webrtc/I420BufferImpl.java b/sdk/android/src/java/org/webrtc/I420BufferImpl.java index 2f545e9d64..48efc257ae 100644 --- a/sdk/android/src/java/org/webrtc/I420BufferImpl.java +++ b/sdk/android/src/java/org/webrtc/I420BufferImpl.java @@ -81,17 +81,20 @@ class I420BufferImpl implements VideoFrame.I420Buffer { @Override public ByteBuffer getDataY() { - return dataY; + // Return a slice to prevent relative reads from changing the position. + return dataY.slice(); } @Override public ByteBuffer getDataU() { - return dataU; + // Return a slice to prevent relative reads from changing the position. + return dataU.slice(); } @Override public ByteBuffer getDataV() { - return dataV; + // Return a slice to prevent relative reads from changing the position. + return dataV.slice(); } @Override diff --git a/sdk/android/src/java/org/webrtc/WrappedNativeI420Buffer.java b/sdk/android/src/java/org/webrtc/WrappedNativeI420Buffer.java index 85d02e6792..ba7f386e19 100644 --- a/sdk/android/src/java/org/webrtc/WrappedNativeI420Buffer.java +++ b/sdk/android/src/java/org/webrtc/WrappedNativeI420Buffer.java @@ -53,17 +53,20 @@ class WrappedNativeI420Buffer implements VideoFrame.I420Buffer { @Override public ByteBuffer getDataY() { - return dataY; + // Return a slice to prevent relative reads from changing the position. + return dataY.slice(); } @Override public ByteBuffer getDataU() { - return dataU; + // Return a slice to prevent relative reads from changing the position. + return dataU.slice(); } @Override public ByteBuffer getDataV() { - return dataV; + // Return a slice to prevent relative reads from changing the position. + return dataV.slice(); } @Override