Reland "Android: Generalize and make TextureBufferImpl public"
This reverts commit 64051d4975b5cee06ab36584f272ff97e35de357. Reason for revert: Fix applied. Original change's description: > Revert "Android: Generalize and make TextureBufferImpl public" > > This reverts commit 28111d7fa0b94e37a5eeba616eb806c65b12560e. > > Reason for revert: Crashes video_quality_loopback_test. > > Original change's description: > > Android: Generalize and make TextureBufferImpl public > > > > This CL generalizes TextureBufferImpl so it's useful from other contexts than > > from a SurfaceTextureHelper, and fixes a bug in cropAndScale(). It also exposes > > the class in the api so that clients don't have to duplicate the logic. > > > > Bug: None > > Change-Id: Ib82aa8bee025ec14de74a7be9d91fd4e5298a248 > > Reviewed-on: https://webrtc-review.googlesource.com/69819 > > Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> > > Commit-Queue: Magnus Jedvert <magjed@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#22875} > > TBR=magjed@webrtc.org,sakal@webrtc.org > > Change-Id: Ica7fc181fec70b8b79f39f0e114eef81a03aa116 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: None > Reviewed-on: https://webrtc-review.googlesource.com/70240 > Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> > Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#22878} TBR=magjed@webrtc.org,sakal@webrtc.org Change-Id: I173d1ccfe0baa80460f796ebaedc51731233108f No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: None Reviewed-on: https://webrtc-review.googlesource.com/70183 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22883}
This commit is contained in:
committed by
Commit Bot
parent
324865a206
commit
1d270f8193
@ -1,98 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.concurrent.atomic.AtomicInteger;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Android texture buffer backed by a SurfaceTextureHelper's texture. The buffer calls
|
||||
* |releaseCallback| when it is released.
|
||||
*/
|
||||
class TextureBufferImpl implements VideoFrame.TextureBuffer {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final Type type;
|
||||
private final int id;
|
||||
private final Matrix transformMatrix;
|
||||
private final SurfaceTextureHelper surfaceTextureHelper;
|
||||
private final RefCountDelegate refCountDelegate;
|
||||
|
||||
public TextureBufferImpl(int width, int height, Type type, int id, Matrix transformMatrix,
|
||||
SurfaceTextureHelper surfaceTextureHelper, @Nullable Runnable releaseCallback) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.transformMatrix = transformMatrix;
|
||||
this.surfaceTextureHelper = surfaceTextureHelper;
|
||||
this.refCountDelegate = new RefCountDelegate(releaseCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoFrame.TextureBuffer.Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTextureId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Matrix getTransformMatrix() {
|
||||
return transformMatrix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoFrame.I420Buffer toI420() {
|
||||
return surfaceTextureHelper.textureToYuv(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void retain() {
|
||||
refCountDelegate.retain();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
refCountDelegate.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoFrame.Buffer cropAndScale(
|
||||
int cropX, int cropY, int cropWidth, int cropHeight, int scaleWidth, int scaleHeight) {
|
||||
retain();
|
||||
Matrix newMatrix = new Matrix(transformMatrix);
|
||||
newMatrix.postScale(cropWidth / (float) width, cropHeight / (float) height);
|
||||
newMatrix.postTranslate(cropX / (float) width, cropY / (float) height);
|
||||
|
||||
return new TextureBufferImpl(
|
||||
scaleWidth, scaleHeight, type, id, newMatrix, surfaceTextureHelper, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
release();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user