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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 break; | 76 break; |
77 default: | 77 default: |
78 throw new RuntimeException("Unknown texture type."); | 78 throw new RuntimeException("Unknown texture type."); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 /** | 82 /** |
83 * 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 |
84 * 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. |
85 */ | 85 */ |
86 public static class YuvUploader { | 86 static class YuvUploader { |
87 // 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. |
88 // 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 |
89 // that handles stride and compare performance with intermediate copy. | 89 // that handles stride and compare performance with intermediate copy. |
90 private ByteBuffer copyBuffer; | 90 private ByteBuffer copyBuffer; |
91 private int[] yuvTextures; | 91 private int[] yuvTextures; |
92 | 92 |
93 /** | 93 /** |
94 * Upload |planes| into OpenGL textures, taking stride into consideration. | 94 * Upload |planes| into OpenGL textures, taking stride into consideration. |
95 * | 95 * |
96 * @return Array of three texture indices corresponding to Y-, U-, and V-pla
ne respectively. | 96 * @return Array of three texture indices corresponding to Y-, U-, and V-pla
ne respectively. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 return yuvTextures; | 137 return yuvTextures; |
138 } | 138 } |
139 | 139 |
140 public int[] uploadFromBuffer(VideoFrame.I420Buffer buffer) { | 140 public int[] uploadFromBuffer(VideoFrame.I420Buffer buffer) { |
141 int[] strides = {buffer.getStrideY(), buffer.getStrideU(), buffer.getStrid
eV()}; | 141 int[] strides = {buffer.getStrideY(), buffer.getStrideU(), buffer.getStrid
eV()}; |
142 ByteBuffer[] planes = {buffer.getDataY(), buffer.getDataU(), buffer.getDat
aV()}; | 142 ByteBuffer[] planes = {buffer.getDataY(), buffer.getDataU(), buffer.getDat
aV()}; |
143 return uploadYuvData(buffer.getWidth(), buffer.getHeight(), strides, plane
s); | 143 return uploadYuvData(buffer.getWidth(), buffer.getHeight(), strides, plane
s); |
144 } | 144 } |
145 | 145 |
| 146 public int[] getYuvTextures() { |
| 147 return yuvTextures; |
| 148 } |
| 149 |
146 /** | 150 /** |
147 * Releases cached resources. Uploader can still be used and the resources w
ill be reallocated | 151 * Releases cached resources. Uploader can still be used and the resources w
ill be reallocated |
148 * on first use. | 152 * on first use. |
149 */ | 153 */ |
150 public void release() { | 154 public void release() { |
151 copyBuffer = null; | 155 copyBuffer = null; |
152 if (yuvTextures != null) { | 156 if (yuvTextures != null) { |
153 GLES20.glDeleteTextures(3, yuvTextures, 0); | 157 GLES20.glDeleteTextures(3, yuvTextures, 0); |
154 yuvTextures = null; | 158 yuvTextures = null; |
155 } | 159 } |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 return new Point(maxDisplayWidth, maxDisplayHeight); | 390 return new Point(maxDisplayWidth, maxDisplayHeight); |
387 } | 391 } |
388 // Each dimension is constrained on max display size and how much we are all
owed to crop. | 392 // Each dimension is constrained on max display size and how much we are all
owed to crop. |
389 final int width = Math.min( | 393 final int width = Math.min( |
390 maxDisplayWidth, Math.round(maxDisplayHeight / minVisibleFraction * vide
oAspectRatio)); | 394 maxDisplayWidth, Math.round(maxDisplayHeight / minVisibleFraction * vide
oAspectRatio)); |
391 final int height = Math.min( | 395 final int height = Math.min( |
392 maxDisplayHeight, Math.round(maxDisplayWidth / minVisibleFraction / vide
oAspectRatio)); | 396 maxDisplayHeight, Math.round(maxDisplayWidth / minVisibleFraction / vide
oAspectRatio)); |
393 return new Point(width, height); | 397 return new Point(width, height); |
394 } | 398 } |
395 } | 399 } |
OLD | NEW |