OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 package org.webrtc; | |
12 | |
13 import android.graphics.Matrix; | |
14 import java.nio.ByteBuffer; | |
15 import org.webrtc.VideoFrame.I420Buffer; | |
16 import org.webrtc.VideoFrame.TextureBuffer; | |
17 | |
18 /** Android OES texture buffer. */ | |
19 class OesTextureBuffer implements TextureBuffer { | |
sakal
2017/07/17 13:44:56
I think this class is inherently tied to SurfaceTe
mellem
2017/07/17 21:57:15
Moved this into SurfaceTextureHelper. I'm not sur
| |
20 private final int id; | |
21 private final int width; | |
22 private final int height; | |
23 private final float[] transformMatrix; | |
24 private final SurfaceTextureHelper helper; | |
25 private int refCount; | |
26 | |
27 OesTextureBuffer( | |
28 int id, int width, int height, float[] transformMatrix, SurfaceTextureHelp er helper) { | |
29 this.id = id; | |
30 this.width = width; | |
31 this.height = height; | |
32 this.transformMatrix = transformMatrix; | |
33 this.helper = helper; | |
34 this.refCount = 1; // Creator implicitly holds a reference. | |
35 } | |
36 | |
37 @Override | |
38 public TextureBuffer.Type getType() { | |
39 return TextureBuffer.Type.OES; | |
40 } | |
41 | |
42 @Override | |
43 public int getTextureId() { | |
44 return id; | |
45 } | |
46 | |
47 @Override | |
48 public int getWidth() { | |
49 return width; | |
50 } | |
51 | |
52 @Override | |
53 public int getHeight() { | |
54 return height; | |
55 } | |
56 | |
57 @Override | |
58 public I420Buffer toI420() { | |
59 // SurfaceTextureHelper requires a stride that is divisible by 8. Round wid th up. | |
60 // See SurfaceTextureHelper for details on the size and format. | |
61 int stride = ((width + 7) / 8) * 8; | |
62 int uvHeight = (height + 1) / 2; | |
63 // Due to the layout used by SurfaceTextureHelper, vPos + stride * uvHeight would overrun the | |
64 // buffer. Add one row at the bottom to compensate for this. There will ne ver be data in the | |
65 // extra row, but now other code does not have to deal with v stride * v hei ght exceeding the | |
66 // buffer's capacity. | |
67 int size = stride * (height + uvHeight + 1); | |
68 ByteBuffer buffer = ByteBuffer.allocateDirect(size); | |
69 helper.textureToYUV(buffer, width, height, stride, id, transformMatrix); | |
70 | |
71 int yPos = 0; | |
72 int uPos = yPos + stride * height; | |
73 // Rows of U and V alternate in the buffer, so V data starts after the first row of U. | |
74 int vPos = yPos + stride / 2; | |
75 | |
76 // SurfaceTextureHelper uses the same stride for Y, U, and V data. | |
77 return new I420BufferImpl( | |
78 buffer, width, height, yPos, stride, uPos, stride, vPos, stride, null); | |
79 } | |
80 | |
81 @Override | |
82 public void retain() { | |
83 ++refCount; | |
84 } | |
85 | |
86 @Override | |
87 public void release() { | |
88 if (--refCount == 0) { | |
89 helper.returnTextureFrame(); | |
90 } | |
91 } | |
92 } | |
OLD | NEW |