X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fthird_party%2Flibjingle%2Fsource%2Ftalk%2Fapp%2Fwebrtc%2Fjava%2Fsrc%2Forg%2Fwebrtc%2FVideoRenderer.java;h=19df137085387032e15a9585ef38133594395d93;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=4cc341a48e15954551cb16090d776a1158810eb9;hpb=7d210d4c7e9ba36e635eabc5b5780495f8a63292;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/third_party/libjingle/source/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java b/src/third_party/libjingle/source/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java index 4cc341a..19df137 100644 --- a/src/third_party/libjingle/source/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java +++ b/src/third_party/libjingle/source/talk/app/webrtc/java/src/org/webrtc/VideoRenderer.java @@ -44,6 +44,9 @@ public class VideoRenderer { public final int height; public final int[] yuvStrides; public final ByteBuffer[] yuvPlanes; + public final boolean yuvFrame; + public Object textureObject; + public int textureId; /** * Construct a frame of the given dimensions with the specified planar @@ -62,25 +65,72 @@ public class VideoRenderer { yuvPlanes[2] = ByteBuffer.allocateDirect(yuvStrides[2] * height); } this.yuvPlanes = yuvPlanes; + this.yuvFrame = true; + } + + /** + * Construct a texture frame of the given dimensions with data in SurfaceTexture + */ + public I420Frame( + int width, int height, Object textureObject, int textureId) { + this.width = width; + this.height = height; + this.yuvStrides = null; + this.yuvPlanes = null; + this.textureObject = textureObject; + this.textureId = textureId; + this.yuvFrame = false; } /** * Copy the planes out of |source| into |this| and return |this|. Calling - * this with mismatched frame dimensions is a programming error and will - * likely crash. + * this with mismatched frame dimensions or frame type is a programming + * error and will likely crash. */ public I420Frame copyFrom(I420Frame source) { - if (!Arrays.equals(yuvStrides, source.yuvStrides) || - width != source.width || height != source.height) { - throw new RuntimeException("Mismatched dimensions! Source: " + + if (source.yuvFrame && yuvFrame) { + if (!Arrays.equals(yuvStrides, source.yuvStrides) || + width != source.width || height != source.height) { + throw new RuntimeException("Mismatched dimensions! Source: " + + source.toString() + ", destination: " + toString()); + } + copyPlane(source.yuvPlanes[0], yuvPlanes[0]); + copyPlane(source.yuvPlanes[1], yuvPlanes[1]); + copyPlane(source.yuvPlanes[2], yuvPlanes[2]); + return this; + } else if (!source.yuvFrame && !yuvFrame) { + textureObject = source.textureObject; + textureId = source.textureId; + return this; + } else { + throw new RuntimeException("Mismatched frame types! Source: " + source.toString() + ", destination: " + toString()); } - copyPlane(source.yuvPlanes[0], yuvPlanes[0]); - copyPlane(source.yuvPlanes[1], yuvPlanes[1]); - copyPlane(source.yuvPlanes[2], yuvPlanes[2]); - return this; } + public I420Frame copyFrom(byte[] yuvData) { + if (yuvData.length < width * height * 3 / 2) { + throw new RuntimeException("Wrong arrays size: " + yuvData.length); + } + if (!yuvFrame) { + throw new RuntimeException("Can not feed yuv data to texture frame"); + } + int planeSize = width * height; + ByteBuffer[] planes = new ByteBuffer[3]; + planes[0] = ByteBuffer.wrap(yuvData, 0, planeSize); + planes[1] = ByteBuffer.wrap(yuvData, planeSize, planeSize / 4); + planes[2] = ByteBuffer.wrap(yuvData, planeSize + planeSize / 4, + planeSize / 4); + for (int i = 0; i < 3; i++) { + yuvPlanes[i].position(0); + yuvPlanes[i].put(planes[i]); + yuvPlanes[i].position(0); + yuvPlanes[i].limit(yuvPlanes[i].capacity()); + } + return this; + } + + @Override public String toString() { return width + "x" + height + ":" + yuvStrides[0] + ":" + yuvStrides[1] + @@ -126,11 +176,16 @@ public class VideoRenderer { } public void dispose() { - free(nativeVideoRenderer); + if (callbacks == null) { + freeGuiVideoRenderer(nativeVideoRenderer); + } else { + freeWrappedVideoRenderer(nativeVideoRenderer); + } } private static native long nativeCreateGuiVideoRenderer(int x, int y); private static native long nativeWrapVideoRenderer(Callbacks callbacks); - private static native void free(long nativeVideoRenderer); + private static native void freeGuiVideoRenderer(long nativeVideoRenderer); + private static native void freeWrappedVideoRenderer(long nativeVideoRenderer); }