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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 import java.nio.ByteBuffer; | 30 import java.nio.ByteBuffer; |
31 | 31 |
32 /** | 32 /** |
33 * Java version of VideoRendererInterface. In addition to allowing clients to | 33 * Java version of VideoRendererInterface. In addition to allowing clients to |
34 * define their own rendering behavior (by passing in a Callbacks object), this | 34 * define their own rendering behavior (by passing in a Callbacks object), this |
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. Frames are only constructed from nati
ve code. */ | 40 * Java version of cricket::VideoFrame. Frames are only constructed from nativ
e code and test |
| 41 * code. |
| 42 */ |
41 public static class I420Frame { | 43 public static class I420Frame { |
42 public final int width; | 44 public final int width; |
43 public final int height; | 45 public final int height; |
44 public final int[] yuvStrides; | 46 public final int[] yuvStrides; |
45 public ByteBuffer[] yuvPlanes; | 47 public ByteBuffer[] yuvPlanes; |
46 public final boolean yuvFrame; | 48 public final boolean yuvFrame; |
47 // Matrix that transforms standard coordinates to their proper sampling loca
tions in | 49 // 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 | 50 // 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 | 51 // cause it to appear different from a normalized texture. This matrix does
not take |
50 // |rotationDegree| into account. | 52 // |rotationDegree| into account. |
51 public final float[] samplingMatrix; | 53 public final float[] samplingMatrix; |
52 public int textureId; | 54 public int textureId; |
53 // Frame pointer in C++. | 55 // Frame pointer in C++. |
54 private long nativeFramePointer; | 56 private long nativeFramePointer; |
55 | 57 |
56 // rotationDegree is the degree that the frame must be rotated clockwisely | 58 // rotationDegree is the degree that the frame must be rotated clockwisely |
57 // to be rendered correctly. | 59 // to be rendered correctly. |
58 public int rotationDegree; | 60 public int rotationDegree; |
59 | 61 |
60 /** | 62 /** |
61 * Construct a frame of the given dimensions with the specified planar data. | 63 * Construct a frame of the given dimensions with the specified planar data. |
62 */ | 64 */ |
63 private I420Frame( | 65 I420Frame(int width, int height, int rotationDegree, int[] yuvStrides, ByteB
uffer[] yuvPlanes, |
64 int width, int height, int rotationDegree, | 66 long nativeFramePointer) { |
65 int[] yuvStrides, ByteBuffer[] yuvPlanes, long nativeFramePointer) { | |
66 this.width = width; | 67 this.width = width; |
67 this.height = height; | 68 this.height = height; |
68 this.yuvStrides = yuvStrides; | 69 this.yuvStrides = yuvStrides; |
69 this.yuvPlanes = yuvPlanes; | 70 this.yuvPlanes = yuvPlanes; |
70 this.yuvFrame = true; | 71 this.yuvFrame = true; |
71 this.rotationDegree = rotationDegree; | 72 this.rotationDegree = rotationDegree; |
72 this.nativeFramePointer = nativeFramePointer; | 73 this.nativeFramePointer = nativeFramePointer; |
73 if (rotationDegree % 90 != 0) { | 74 if (rotationDegree % 90 != 0) { |
74 throw new IllegalArgumentException("Rotation degree not multiple of 90:
" + rotationDegree); | 75 throw new IllegalArgumentException("Rotation degree not multiple of 90:
" + rotationDegree); |
75 } | 76 } |
76 // The convention in WebRTC is that the first element in a ByteBuffer corr
esponds to the | 77 // 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 // 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 // bottom-left corner. This discrepancy is corrected by setting a vertical
flip as sampling |
79 // matrix. | 80 // matrix. |
80 samplingMatrix = new float[] { | 81 samplingMatrix = new float[] { |
81 1, 0, 0, 0, | 82 1, 0, 0, 0, |
82 0, -1, 0, 0, | 83 0, -1, 0, 0, |
83 0, 0, 1, 0, | 84 0, 0, 1, 0, |
84 0, 1, 0, 1}; | 85 0, 1, 0, 1}; |
85 } | 86 } |
86 | 87 |
87 /** | 88 /** |
88 * Construct a texture frame of the given dimensions with data in SurfaceTex
ture | 89 * Construct a texture frame of the given dimensions with data in SurfaceTex
ture |
89 */ | 90 */ |
90 private I420Frame( | 91 I420Frame(int width, int height, int rotationDegree, int textureId, float[]
samplingMatrix, |
91 int width, int height, int rotationDegree, | 92 long nativeFramePointer) { |
92 int textureId, float[] samplingMatrix, long nativeFramePointer) { | |
93 this.width = width; | 93 this.width = width; |
94 this.height = height; | 94 this.height = height; |
95 this.yuvStrides = null; | 95 this.yuvStrides = null; |
96 this.yuvPlanes = null; | 96 this.yuvPlanes = null; |
97 this.samplingMatrix = samplingMatrix; | 97 this.samplingMatrix = samplingMatrix; |
98 this.textureId = textureId; | 98 this.textureId = textureId; |
99 this.yuvFrame = false; | 99 this.yuvFrame = false; |
100 this.rotationDegree = rotationDegree; | 100 this.rotationDegree = rotationDegree; |
101 this.nativeFramePointer = nativeFramePointer; | 101 this.nativeFramePointer = nativeFramePointer; |
102 if (rotationDegree % 90 != 0) { | 102 if (rotationDegree % 90 != 0) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } | 181 } |
182 | 182 |
183 private static native long nativeCreateGuiVideoRenderer(int x, int y); | 183 private static native long nativeCreateGuiVideoRenderer(int x, int y); |
184 private static native long nativeWrapVideoRenderer(Callbacks callbacks); | 184 private static native long nativeWrapVideoRenderer(Callbacks callbacks); |
185 | 185 |
186 private static native void freeGuiVideoRenderer(long nativeVideoRenderer); | 186 private static native void freeGuiVideoRenderer(long nativeVideoRenderer); |
187 private static native void freeWrappedVideoRenderer(long nativeVideoRenderer); | 187 private static native void freeWrappedVideoRenderer(long nativeVideoRenderer); |
188 | 188 |
189 private static native void releaseNativeFrame(long nativeFramePointer); | 189 private static native void releaseNativeFrame(long nativeFramePointer); |
190 } | 190 } |
OLD | NEW |