Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Unified Diff: webrtc/sdk/android/src/java/org/webrtc/OesTextureBuffer.java

Issue 2977643002: Add texture support to HardwareVideoDecoder. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/sdk/android/src/java/org/webrtc/OesTextureBuffer.java
diff --git a/webrtc/sdk/android/src/java/org/webrtc/OesTextureBuffer.java b/webrtc/sdk/android/src/java/org/webrtc/OesTextureBuffer.java
new file mode 100644
index 0000000000000000000000000000000000000000..8f2c4858205ce39a5c89e3a5518090272182256c
--- /dev/null
+++ b/webrtc/sdk/android/src/java/org/webrtc/OesTextureBuffer.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+package org.webrtc;
+
+import android.graphics.Matrix;
+import java.nio.ByteBuffer;
+import org.webrtc.VideoFrame.I420Buffer;
+import org.webrtc.VideoFrame.TextureBuffer;
+
+/** Android OES texture buffer. */
+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
+ private final int id;
+ private final int width;
+ private final int height;
+ private final float[] transformMatrix;
+ private final SurfaceTextureHelper helper;
+ private int refCount;
+
+ OesTextureBuffer(
+ int id, int width, int height, float[] transformMatrix, SurfaceTextureHelper helper) {
+ this.id = id;
+ this.width = width;
+ this.height = height;
+ this.transformMatrix = transformMatrix;
+ this.helper = helper;
+ this.refCount = 1; // Creator implicitly holds a reference.
+ }
+
+ @Override
+ public TextureBuffer.Type getType() {
+ return TextureBuffer.Type.OES;
+ }
+
+ @Override
+ public int getTextureId() {
+ return id;
+ }
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ @Override
+ public int getHeight() {
+ return height;
+ }
+
+ @Override
+ public I420Buffer toI420() {
+ // SurfaceTextureHelper requires a stride that is divisible by 8. Round width up.
+ // See SurfaceTextureHelper for details on the size and format.
+ int stride = ((width + 7) / 8) * 8;
+ int uvHeight = (height + 1) / 2;
+ // Due to the layout used by SurfaceTextureHelper, vPos + stride * uvHeight would overrun the
+ // buffer. Add one row at the bottom to compensate for this. There will never be data in the
+ // extra row, but now other code does not have to deal with v stride * v height exceeding the
+ // buffer's capacity.
+ int size = stride * (height + uvHeight + 1);
+ ByteBuffer buffer = ByteBuffer.allocateDirect(size);
+ helper.textureToYUV(buffer, width, height, stride, id, transformMatrix);
+
+ int yPos = 0;
+ int uPos = yPos + stride * height;
+ // Rows of U and V alternate in the buffer, so V data starts after the first row of U.
+ int vPos = yPos + stride / 2;
+
+ // SurfaceTextureHelper uses the same stride for Y, U, and V data.
+ return new I420BufferImpl(
+ buffer, width, height, yPos, stride, uPos, stride, vPos, stride, null);
+ }
+
+ @Override
+ public void retain() {
+ ++refCount;
+ }
+
+ @Override
+ public void release() {
+ if (--refCount == 0) {
+ helper.returnTextureFrame();
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698