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 28 matching lines...) Expand all Loading... |
39 /** | 39 /** |
40 * Java version of cricket::VideoFrame. Frames are only constructed from nativ
e code and test | 40 * Java version of cricket::VideoFrame. Frames are only constructed from nativ
e code and test |
41 * code. | 41 * code. |
42 */ | 42 */ |
43 public static class I420Frame { | 43 public static class I420Frame { |
44 public final int width; | 44 public final int width; |
45 public final int height; | 45 public final int height; |
46 public final int[] yuvStrides; | 46 public final int[] yuvStrides; |
47 public ByteBuffer[] yuvPlanes; | 47 public ByteBuffer[] yuvPlanes; |
48 public final boolean yuvFrame; | 48 public final boolean yuvFrame; |
49 // Matrix that transforms standard coordinates to their proper sampling loca
tions in | 49 public Object textureObject; |
50 // the texture. This transform compensates for any properties of the video s
ource that | |
51 // cause it to appear different from a normalized texture. This matrix does
not take | |
52 // |rotationDegree| into account. | |
53 public final float[] samplingMatrix; | |
54 public int textureId; | 50 public int textureId; |
55 // Frame pointer in C++. | 51 // Frame pointer in C++. |
56 private long nativeFramePointer; | 52 private long nativeFramePointer; |
57 | 53 |
58 // rotationDegree is the degree that the frame must be rotated clockwisely | 54 // rotationDegree is the degree that the frame must be rotated clockwisely |
59 // to be rendered correctly. | 55 // to be rendered correctly. |
60 public int rotationDegree; | 56 public int rotationDegree; |
61 | 57 |
62 /** | 58 /** |
63 * Construct a frame of the given dimensions with the specified planar data. | 59 * Construct a frame of the given dimensions with the specified planar data. |
64 */ | 60 */ |
65 I420Frame(int width, int height, int rotationDegree, int[] yuvStrides, ByteB
uffer[] yuvPlanes, | 61 I420Frame(int width, int height, int rotationDegree, int[] yuvStrides, ByteB
uffer[] yuvPlanes, |
66 long nativeFramePointer) { | 62 long nativeFramePointer) { |
67 this.width = width; | 63 this.width = width; |
68 this.height = height; | 64 this.height = height; |
69 this.yuvStrides = yuvStrides; | 65 this.yuvStrides = yuvStrides; |
70 this.yuvPlanes = yuvPlanes; | 66 this.yuvPlanes = yuvPlanes; |
71 this.yuvFrame = true; | 67 this.yuvFrame = true; |
72 this.rotationDegree = rotationDegree; | 68 this.rotationDegree = rotationDegree; |
73 this.nativeFramePointer = nativeFramePointer; | 69 this.nativeFramePointer = nativeFramePointer; |
74 if (rotationDegree % 90 != 0) { | 70 if (rotationDegree % 90 != 0) { |
75 throw new IllegalArgumentException("Rotation degree not multiple of 90:
" + rotationDegree); | 71 throw new IllegalArgumentException("Rotation degree not multiple of 90:
" + rotationDegree); |
76 } | 72 } |
77 // The convention in WebRTC is that the first element in a ByteBuffer corr
esponds to the | |
78 // top-left corner of the image, but in glTexImage2D() the first element c
orresponds to the | |
79 // bottom-left corner. This discrepancy is corrected by setting a vertical
flip as sampling | |
80 // matrix. | |
81 samplingMatrix = new float[] { | |
82 1, 0, 0, 0, | |
83 0, -1, 0, 0, | |
84 0, 0, 1, 0, | |
85 0, 1, 0, 1}; | |
86 } | 73 } |
87 | 74 |
88 /** | 75 /** |
89 * Construct a texture frame of the given dimensions with data in SurfaceTex
ture | 76 * Construct a texture frame of the given dimensions with data in SurfaceTex
ture |
90 */ | 77 */ |
91 I420Frame(int width, int height, int rotationDegree, int textureId, float[]
samplingMatrix, | 78 I420Frame( |
92 long nativeFramePointer) { | 79 int width, int height, int rotationDegree, |
| 80 Object textureObject, int textureId, long nativeFramePointer) { |
93 this.width = width; | 81 this.width = width; |
94 this.height = height; | 82 this.height = height; |
95 this.yuvStrides = null; | 83 this.yuvStrides = null; |
96 this.yuvPlanes = null; | 84 this.yuvPlanes = null; |
97 this.samplingMatrix = samplingMatrix; | 85 this.textureObject = textureObject; |
98 this.textureId = textureId; | 86 this.textureId = textureId; |
99 this.yuvFrame = false; | 87 this.yuvFrame = false; |
100 this.rotationDegree = rotationDegree; | 88 this.rotationDegree = rotationDegree; |
101 this.nativeFramePointer = nativeFramePointer; | 89 this.nativeFramePointer = nativeFramePointer; |
102 if (rotationDegree % 90 != 0) { | 90 if (rotationDegree % 90 != 0) { |
103 throw new IllegalArgumentException("Rotation degree not multiple of 90:
" + rotationDegree); | 91 throw new IllegalArgumentException("Rotation degree not multiple of 90:
" + rotationDegree); |
104 } | 92 } |
105 } | 93 } |
106 | 94 |
107 public int rotatedWidth() { | 95 public int rotatedWidth() { |
(...skipping 22 matching lines...) Expand all Loading... |
130 // is responsible for signaling when it is done with |frame| by calling | 118 // is responsible for signaling when it is done with |frame| by calling |
131 // renderFrameDone(frame). | 119 // renderFrameDone(frame). |
132 public void renderFrame(I420Frame frame); | 120 public void renderFrame(I420Frame frame); |
133 } | 121 } |
134 | 122 |
135 /** | 123 /** |
136 * This must be called after every renderFrame() to release the frame. | 124 * This must be called after every renderFrame() to release the frame. |
137 */ | 125 */ |
138 public static void renderFrameDone(I420Frame frame) { | 126 public static void renderFrameDone(I420Frame frame) { |
139 frame.yuvPlanes = null; | 127 frame.yuvPlanes = null; |
| 128 frame.textureObject = null; |
140 frame.textureId = 0; | 129 frame.textureId = 0; |
141 if (frame.nativeFramePointer != 0) { | 130 if (frame.nativeFramePointer != 0) { |
142 releaseNativeFrame(frame.nativeFramePointer); | 131 releaseNativeFrame(frame.nativeFramePointer); |
143 frame.nativeFramePointer = 0; | 132 frame.nativeFramePointer = 0; |
144 } | 133 } |
145 } | 134 } |
146 | 135 |
147 // |this| either wraps a native (GUI) renderer or a client-supplied Callbacks | 136 // |this| either wraps a native (GUI) renderer or a client-supplied Callbacks |
148 // (Java) implementation; this is indicated by |isWrappedVideoRenderer|. | 137 // (Java) implementation; this is indicated by |isWrappedVideoRenderer|. |
149 long nativeVideoRenderer; | 138 long nativeVideoRenderer; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 170 } |
182 | 171 |
183 private static native long nativeCreateGuiVideoRenderer(int x, int y); | 172 private static native long nativeCreateGuiVideoRenderer(int x, int y); |
184 private static native long nativeWrapVideoRenderer(Callbacks callbacks); | 173 private static native long nativeWrapVideoRenderer(Callbacks callbacks); |
185 | 174 |
186 private static native void freeGuiVideoRenderer(long nativeVideoRenderer); | 175 private static native void freeGuiVideoRenderer(long nativeVideoRenderer); |
187 private static native void freeWrappedVideoRenderer(long nativeVideoRenderer); | 176 private static native void freeWrappedVideoRenderer(long nativeVideoRenderer); |
188 | 177 |
189 private static native void releaseNativeFrame(long nativeFramePointer); | 178 private static native void releaseNativeFrame(long nativeFramePointer); |
190 } | 179 } |
OLD | NEW |