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