Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Unified Diff: talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java

Issue 1257043004: AppRTCDemo: Render each video in a separate SurfaceView (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java
diff --git a/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java b/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java
index 401640b463bfdfff7f832ebf75ce73100a0b40fb..f4e2eabc9b4d28d57a8134fcd46b4eb57d40a57e 100644
--- a/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java
+++ b/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java
@@ -42,10 +42,12 @@ public class VideoRenderer {
public final int width;
public final int height;
public final int[] yuvStrides;
- public final ByteBuffer[] yuvPlanes;
+ public ByteBuffer[] yuvPlanes;
public final boolean yuvFrame;
public Object textureObject;
public int textureId;
+ // If |nativeFramePointer| is non-zero, the memory is allocated on the C++ side.
+ private long nativeFramePointer;
// rotationDegree is the degree that the frame must be rotated clockwisely
// to be rendered correctly.
@@ -58,7 +60,7 @@ public class VideoRenderer {
*/
public I420Frame(
int width, int height, int rotationDegree,
- int[] yuvStrides, ByteBuffer[] yuvPlanes) {
+ int[] yuvStrides, ByteBuffer[] yuvPlanes, long nativeFramePointer) {
this.width = width;
this.height = height;
this.yuvStrides = yuvStrides;
@@ -71,6 +73,7 @@ public class VideoRenderer {
this.yuvPlanes = yuvPlanes;
this.yuvFrame = true;
this.rotationDegree = rotationDegree;
+ this.nativeFramePointer = nativeFramePointer;
if (rotationDegree % 90 != 0) {
throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree);
}
@@ -81,7 +84,7 @@ public class VideoRenderer {
*/
public I420Frame(
int width, int height, int rotationDegree,
- Object textureObject, int textureId) {
+ Object textureObject, int textureId, long nativeFramePointer) {
this.width = width;
this.height = height;
this.yuvStrides = null;
@@ -90,11 +93,46 @@ public class VideoRenderer {
this.textureId = textureId;
this.yuvFrame = false;
this.rotationDegree = rotationDegree;
+ this.nativeFramePointer = nativeFramePointer;
if (rotationDegree % 90 != 0) {
throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree);
}
}
+ /**
+ * Shallow copy constructor.
+ */
+ private I420Frame(I420Frame source) {
AlexG 2015/08/04 00:27:23 This implementation will do frame memory allocatio
magjed_webrtc 2015/08/04 17:05:05 It will not allocate or copy the pixel data, it wi
+ width = source.width;
+ height = source.height;
+ yuvStrides = source.yuvStrides;
+ yuvPlanes = source.yuvPlanes;
+ yuvFrame = source.yuvFrame;
+ textureObject = source.textureObject;
+ textureId = source.textureId;
+ rotationDegree = source.rotationDegree;
+ // If source.nativeFramePointer == 0, then the memory is managed by Java's garbage collector.
+ // Otherwise, we need to ask C++ to make a shallow copy.
+ nativeFramePointer = (source.nativeFramePointer == 0)
+ ? 0
+ : shallowCopyNativeFrame(source.nativeFramePointer);
+ }
+
+ // Every shallow copy should be released to make sure we don't leak memory in C++.
+ public I420Frame shallowCopy() {
+ return new I420Frame(this);
+ }
+
+ public void release() {
AlexG 2015/08/04 00:27:23 I would add a flag here to avoid accidental case i
magjed_webrtc 2015/08/04 17:05:05 Ok, how about this interface instead; for every ca
AlexG 2015/08/05 00:47:11 If you are making a copy of only pointers in Video
magjed_webrtc 2015/08/07 17:14:50 It is possible to make async rendering with VideoR
+ yuvPlanes = null;
+ textureObject = null;
+ textureId = 0;
+ if (nativeFramePointer != 0) {
+ releaseNativeFrame(nativeFramePointer);
+ nativeFramePointer = 0;
+ }
+ }
+
public int rotatedWidth() {
return (rotationDegree % 180 == 0) ? width : height;
}
@@ -212,4 +250,7 @@ public class VideoRenderer {
private static native void freeGuiVideoRenderer(long nativeVideoRenderer);
private static native void freeWrappedVideoRenderer(long nativeVideoRenderer);
+
+ private static native long shallowCopyNativeFrame(long nativeFramePointer);
+ private static native void releaseNativeFrame(long nativeFramePointer);
}

Powered by Google App Engine
This is Rietveld 408576698