OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 */ | 27 */ |
28 public void onFirstFrameRendered(); | 28 public void onFirstFrameRendered(); |
29 | 29 |
30 /** | 30 /** |
31 * Callback fired when rendered frame resolution or rotation has changed. | 31 * Callback fired when rendered frame resolution or rotation has changed. |
32 */ | 32 */ |
33 public void onFrameResolutionChanged(int videoWidth, int videoHeight, int ro
tation); | 33 public void onFrameResolutionChanged(int videoWidth, int videoHeight, int ro
tation); |
34 } | 34 } |
35 | 35 |
36 /** Interface for rendering frames on an EGLSurface. */ | 36 /** Interface for rendering frames on an EGLSurface. */ |
37 @SuppressWarnings("StaticOrDefaultInterfaceMethod") | |
38 public static interface GlDrawer { | 37 public static interface GlDrawer { |
39 /** | 38 /** |
40 * Functions for drawing frames with different sources. The rendering surfac
e target is | 39 * Functions for drawing frames with different sources. The rendering surfac
e target is |
41 * implied by the current EGL context of the calling thread and requires no
explicit argument. | 40 * implied by the current EGL context of the calling thread and requires no
explicit argument. |
42 * The coordinates specify the viewport location on the surface target. | 41 * The coordinates specify the viewport location on the surface target. |
43 */ | 42 */ |
44 void drawOes(int oesTextureId, float[] texMatrix, int frameWidth, int frameH
eight, | 43 void drawOes(int oesTextureId, float[] texMatrix, int frameWidth, int frameH
eight, |
45 int viewportX, int viewportY, int viewportWidth, int viewportHeight); | 44 int viewportX, int viewportY, int viewportWidth, int viewportHeight); |
46 void drawRgb(int textureId, float[] texMatrix, int frameWidth, int frameHeig
ht, int viewportX, | 45 void drawRgb(int textureId, float[] texMatrix, int frameWidth, int frameHeig
ht, int viewportX, |
47 int viewportY, int viewportWidth, int viewportHeight); | 46 int viewportY, int viewportWidth, int viewportHeight); |
48 void drawYuv(int[] yuvTextures, float[] texMatrix, int frameWidth, int frame
Height, | 47 void drawYuv(int[] yuvTextures, float[] texMatrix, int frameWidth, int frame
Height, |
49 int viewportX, int viewportY, int viewportWidth, int viewportHeight); | 48 int viewportX, int viewportY, int viewportWidth, int viewportHeight); |
50 | 49 |
51 /** | 50 /** |
52 * Draws a VideoFrame.TextureBuffer. Default implementation calls either dra
wOes or drawRgb | 51 * Release all GL resources. This needs to be done manually, otherwise resou
rces may leak. |
53 * depending on the type of the buffer. You can supply an additional render
matrix. This is | |
54 * used multiplied together with the transformation matrix of the frame. (M
= renderMatrix * | |
55 * transformationMatrix) | |
56 */ | 52 */ |
57 default void | 53 void release(); |
58 drawTexture(VideoFrame.TextureBuffer buffer, android.graphics.Matrix rende
rMatrix, | |
59 int frameWidth, int frameHeight, int viewportX, int viewportY, int vie
wportWidth, | |
60 int viewportHeight) { | |
61 android.graphics.Matrix finalMatrix = | |
62 new android.graphics.Matrix(buffer.getTransformMatrix()); | |
63 finalMatrix.preConcat(renderMatrix); | |
64 float[] finalGlMatrix = convertMatrixFromAndroidGraphicsMatrix(finalMatr
ix); | |
65 switch (buffer.getType()) { | |
66 case OES: | |
67 drawOes(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHeigh
t, viewportX, | |
68 viewportY, viewportWidth, viewportHeight); | |
69 break; | |
70 case RGB: | |
71 drawRgb(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHeigh
t, viewportX, | |
72 viewportY, viewportWidth, viewportHeight); | |
73 break; | |
74 default: | |
75 throw new RuntimeException("Unknown texture type."); | |
76 } | |
77 } | |
78 | |
79 /** | |
80 * Release all GL resources. This needs to be done manually, otherwise res
ources may leak. | |
81 */ | |
82 void release(); | |
83 } | 54 } |
84 | 55 |
85 /** | 56 /** |
| 57 * Draws a VideoFrame.TextureBuffer. Calls either drawer.drawOes or drawer.dra
wRgb |
| 58 * depending on the type of the buffer. You can supply an additional render ma
trix. This is |
| 59 * used multiplied together with the transformation matrix of the frame. (M =
renderMatrix * |
| 60 * transformationMatrix) |
| 61 */ |
| 62 static void drawTexture(GlDrawer drawer, VideoFrame.TextureBuffer buffer, |
| 63 android.graphics.Matrix renderMatrix, int frameWidth, int frameHeight, int
viewportX, |
| 64 int viewportY, int viewportWidth, int viewportHeight) { |
| 65 android.graphics.Matrix finalMatrix = new android.graphics.Matrix(buffer.get
TransformMatrix()); |
| 66 finalMatrix.preConcat(renderMatrix); |
| 67 float[] finalGlMatrix = convertMatrixFromAndroidGraphicsMatrix(finalMatrix); |
| 68 switch (buffer.getType()) { |
| 69 case OES: |
| 70 drawer.drawOes(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHe
ight, viewportX, |
| 71 viewportY, viewportWidth, viewportHeight); |
| 72 break; |
| 73 case RGB: |
| 74 drawer.drawRgb(buffer.getTextureId(), finalGlMatrix, frameWidth, frameHe
ight, viewportX, |
| 75 viewportY, viewportWidth, viewportHeight); |
| 76 break; |
| 77 default: |
| 78 throw new RuntimeException("Unknown texture type."); |
| 79 } |
| 80 } |
| 81 |
| 82 /** |
86 * Helper class for uploading YUV bytebuffer frames to textures that handles s
tride > width. This | 83 * Helper class for uploading YUV bytebuffer frames to textures that handles s
tride > width. This |
87 * class keeps an internal ByteBuffer to avoid unnecessary allocations for int
ermediate copies. | 84 * class keeps an internal ByteBuffer to avoid unnecessary allocations for int
ermediate copies. |
88 */ | 85 */ |
89 public static class YuvUploader { | 86 public static class YuvUploader { |
90 // Intermediate copy buffer for uploading yuv frames that are not packed, i.
e. stride > width. | 87 // Intermediate copy buffer for uploading yuv frames that are not packed, i.
e. stride > width. |
91 // TODO(magjed): Investigate when GL_UNPACK_ROW_LENGTH is available, or make
a custom shader | 88 // TODO(magjed): Investigate when GL_UNPACK_ROW_LENGTH is available, or make
a custom shader |
92 // that handles stride and compare performance with intermediate copy. | 89 // that handles stride and compare performance with intermediate copy. |
93 private ByteBuffer copyBuffer; | 90 private ByteBuffer copyBuffer; |
94 private int[] yuvTextures; | 91 private int[] yuvTextures; |
95 | 92 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 return new Point(maxDisplayWidth, maxDisplayHeight); | 386 return new Point(maxDisplayWidth, maxDisplayHeight); |
390 } | 387 } |
391 // Each dimension is constrained on max display size and how much we are all
owed to crop. | 388 // Each dimension is constrained on max display size and how much we are all
owed to crop. |
392 final int width = Math.min( | 389 final int width = Math.min( |
393 maxDisplayWidth, Math.round(maxDisplayHeight / minVisibleFraction * vide
oAspectRatio)); | 390 maxDisplayWidth, Math.round(maxDisplayHeight / minVisibleFraction * vide
oAspectRatio)); |
394 final int height = Math.min( | 391 final int height = Math.min( |
395 maxDisplayHeight, Math.round(maxDisplayWidth / minVisibleFraction / vide
oAspectRatio)); | 392 maxDisplayHeight, Math.round(maxDisplayWidth / minVisibleFraction / vide
oAspectRatio)); |
396 return new Point(width, height); | 393 return new Point(width, height); |
397 } | 394 } |
398 } | 395 } |
OLD | NEW |