OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 24 matching lines...) Expand all Loading... | |
35 * class also provides a createGui() method for creating a GUI-rendering window | 35 * class also provides a createGui() method for creating a GUI-rendering window |
36 * on various platforms. | 36 * on various platforms. |
37 */ | 37 */ |
38 public class VideoRenderer { | 38 public class VideoRenderer { |
39 | 39 |
40 /** Java version of cricket::VideoFrame. */ | 40 /** Java version of cricket::VideoFrame. */ |
41 public static class I420Frame { | 41 public static class I420Frame { |
42 public final int width; | 42 public final int width; |
43 public final int height; | 43 public final int height; |
44 public final int[] yuvStrides; | 44 public final int[] yuvStrides; |
45 public final ByteBuffer[] yuvPlanes; | 45 public ByteBuffer[] yuvPlanes; |
46 public final boolean yuvFrame; | 46 public final boolean yuvFrame; |
47 public Object textureObject; | 47 public Object textureObject; |
48 public int textureId; | 48 public int textureId; |
49 // If |nativeFramePointer| is non-zero, the memory is allocated on the C++ s ide. | |
50 private long nativeFramePointer; | |
49 | 51 |
50 // rotationDegree is the degree that the frame must be rotated clockwisely | 52 // rotationDegree is the degree that the frame must be rotated clockwisely |
51 // to be rendered correctly. | 53 // to be rendered correctly. |
52 public int rotationDegree; | 54 public int rotationDegree; |
53 | 55 |
54 /** | 56 /** |
55 * Construct a frame of the given dimensions with the specified planar | 57 * Construct a frame of the given dimensions with the specified planar |
56 * data. If |yuvPlanes| is null, new planes of the appropriate sizes are | 58 * data. If |yuvPlanes| is null, new planes of the appropriate sizes are |
57 * allocated. | 59 * allocated. |
58 */ | 60 */ |
59 public I420Frame( | 61 public I420Frame( |
60 int width, int height, int rotationDegree, | 62 int width, int height, int rotationDegree, |
61 int[] yuvStrides, ByteBuffer[] yuvPlanes) { | 63 int[] yuvStrides, ByteBuffer[] yuvPlanes, long nativeFramePointer) { |
62 this.width = width; | 64 this.width = width; |
63 this.height = height; | 65 this.height = height; |
64 this.yuvStrides = yuvStrides; | 66 this.yuvStrides = yuvStrides; |
65 if (yuvPlanes == null) { | 67 if (yuvPlanes == null) { |
66 yuvPlanes = new ByteBuffer[3]; | 68 yuvPlanes = new ByteBuffer[3]; |
67 yuvPlanes[0] = ByteBuffer.allocateDirect(yuvStrides[0] * height); | 69 yuvPlanes[0] = ByteBuffer.allocateDirect(yuvStrides[0] * height); |
68 yuvPlanes[1] = ByteBuffer.allocateDirect(yuvStrides[1] * height / 2); | 70 yuvPlanes[1] = ByteBuffer.allocateDirect(yuvStrides[1] * height / 2); |
69 yuvPlanes[2] = ByteBuffer.allocateDirect(yuvStrides[2] * height / 2); | 71 yuvPlanes[2] = ByteBuffer.allocateDirect(yuvStrides[2] * height / 2); |
70 } | 72 } |
71 this.yuvPlanes = yuvPlanes; | 73 this.yuvPlanes = yuvPlanes; |
72 this.yuvFrame = true; | 74 this.yuvFrame = true; |
73 this.rotationDegree = rotationDegree; | 75 this.rotationDegree = rotationDegree; |
76 this.nativeFramePointer = nativeFramePointer; | |
74 if (rotationDegree % 90 != 0) { | 77 if (rotationDegree % 90 != 0) { |
75 throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree); | 78 throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree); |
76 } | 79 } |
77 } | 80 } |
78 | 81 |
79 /** | 82 /** |
80 * Construct a texture frame of the given dimensions with data in SurfaceTex ture | 83 * Construct a texture frame of the given dimensions with data in SurfaceTex ture |
81 */ | 84 */ |
82 public I420Frame( | 85 public I420Frame( |
83 int width, int height, int rotationDegree, | 86 int width, int height, int rotationDegree, |
84 Object textureObject, int textureId) { | 87 Object textureObject, int textureId, long nativeFramePointer) { |
85 this.width = width; | 88 this.width = width; |
86 this.height = height; | 89 this.height = height; |
87 this.yuvStrides = null; | 90 this.yuvStrides = null; |
88 this.yuvPlanes = null; | 91 this.yuvPlanes = null; |
89 this.textureObject = textureObject; | 92 this.textureObject = textureObject; |
90 this.textureId = textureId; | 93 this.textureId = textureId; |
91 this.yuvFrame = false; | 94 this.yuvFrame = false; |
92 this.rotationDegree = rotationDegree; | 95 this.rotationDegree = rotationDegree; |
96 this.nativeFramePointer = nativeFramePointer; | |
93 if (rotationDegree % 90 != 0) { | 97 if (rotationDegree % 90 != 0) { |
94 throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree); | 98 throw new IllegalArgumentException("Rotation degree not multiple of 90: " + rotationDegree); |
95 } | 99 } |
96 } | 100 } |
97 | 101 |
102 /** | |
103 * Shallow copy constructor. | |
104 */ | |
105 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
| |
106 width = source.width; | |
107 height = source.height; | |
108 yuvStrides = source.yuvStrides; | |
109 yuvPlanes = source.yuvPlanes; | |
110 yuvFrame = source.yuvFrame; | |
111 textureObject = source.textureObject; | |
112 textureId = source.textureId; | |
113 rotationDegree = source.rotationDegree; | |
114 // If source.nativeFramePointer == 0, then the memory is managed by Java's garbage collector. | |
115 // Otherwise, we need to ask C++ to make a shallow copy. | |
116 nativeFramePointer = (source.nativeFramePointer == 0) | |
117 ? 0 | |
118 : shallowCopyNativeFrame(source.nativeFramePointer); | |
119 } | |
120 | |
121 // Every shallow copy should be released to make sure we don't leak memory i n C++. | |
122 public I420Frame shallowCopy() { | |
123 return new I420Frame(this); | |
124 } | |
125 | |
126 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
| |
127 yuvPlanes = null; | |
128 textureObject = null; | |
129 textureId = 0; | |
130 if (nativeFramePointer != 0) { | |
131 releaseNativeFrame(nativeFramePointer); | |
132 nativeFramePointer = 0; | |
133 } | |
134 } | |
135 | |
98 public int rotatedWidth() { | 136 public int rotatedWidth() { |
99 return (rotationDegree % 180 == 0) ? width : height; | 137 return (rotationDegree % 180 == 0) ? width : height; |
100 } | 138 } |
101 | 139 |
102 public int rotatedHeight() { | 140 public int rotatedHeight() { |
103 return (rotationDegree % 180 == 0) ? height : width; | 141 return (rotationDegree % 180 == 0) ? height : width; |
104 } | 142 } |
105 | 143 |
106 /** | 144 /** |
107 * Copy the planes out of |source| into |this| and return |this|. Calling | 145 * Copy the planes out of |source| into |this| and return |this|. Calling |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 } else { | 243 } else { |
206 freeWrappedVideoRenderer(nativeVideoRenderer); | 244 freeWrappedVideoRenderer(nativeVideoRenderer); |
207 } | 245 } |
208 } | 246 } |
209 | 247 |
210 private static native long nativeCreateGuiVideoRenderer(int x, int y); | 248 private static native long nativeCreateGuiVideoRenderer(int x, int y); |
211 private static native long nativeWrapVideoRenderer(Callbacks callbacks); | 249 private static native long nativeWrapVideoRenderer(Callbacks callbacks); |
212 | 250 |
213 private static native void freeGuiVideoRenderer(long nativeVideoRenderer); | 251 private static native void freeGuiVideoRenderer(long nativeVideoRenderer); |
214 private static native void freeWrappedVideoRenderer(long nativeVideoRenderer); | 252 private static native void freeWrappedVideoRenderer(long nativeVideoRenderer); |
253 | |
254 private static native long shallowCopyNativeFrame(long nativeFramePointer); | |
255 private static native void releaseNativeFrame(long nativeFramePointer); | |
215 } | 256 } |
OLD | NEW |