mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
fix: make BitmapOverlay constructor public
So developers can subclass it #minor-release PiperOrigin-RevId: 586638134
This commit is contained in:
parent
a2a4ef5f40
commit
5b3491082b
1 changed files with 49 additions and 49 deletions
|
|
@ -47,7 +47,7 @@ public abstract class BitmapOverlay extends TextureOverlay {
|
||||||
private int lastBitmapGenerationId;
|
private int lastBitmapGenerationId;
|
||||||
private @Nullable Bitmap lastBitmap;
|
private @Nullable Bitmap lastBitmap;
|
||||||
|
|
||||||
/* package */ BitmapOverlay() {
|
public BitmapOverlay() {
|
||||||
float[] temp = GlUtil.create4x4IdentityMatrix();
|
float[] temp = GlUtil.create4x4IdentityMatrix();
|
||||||
Matrix.scaleM(temp, /* offset */ 0, /* x= */ 1f, /* y= */ -1f, /* z= */ 1f);
|
Matrix.scaleM(temp, /* offset */ 0, /* x= */ 1f, /* y= */ -1f, /* z= */ 1f);
|
||||||
flipVerticallyMatrix = temp;
|
flipVerticallyMatrix = temp;
|
||||||
|
|
@ -55,54 +55,6 @@ public abstract class BitmapOverlay extends TextureOverlay {
|
||||||
lastTextureId = C.INDEX_UNSET;
|
lastTextureId = C.INDEX_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the overlay bitmap displayed at the specified timestamp.
|
|
||||||
*
|
|
||||||
* @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
|
|
||||||
* @throws VideoFrameProcessingException If an error occurs while processing or drawing the frame.
|
|
||||||
*/
|
|
||||||
public abstract Bitmap getBitmap(long presentationTimeUs) throws VideoFrameProcessingException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*
|
|
||||||
* <p>Gets the width and height of the cached bitmap.
|
|
||||||
*
|
|
||||||
* @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Size getTextureSize(long presentationTimeUs) {
|
|
||||||
return new Size(checkNotNull(lastBitmap).getWidth(), checkNotNull(lastBitmap).getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTextureId(long presentationTimeUs) throws VideoFrameProcessingException {
|
|
||||||
Bitmap bitmap = getBitmap(presentationTimeUs);
|
|
||||||
int generationId = bitmap.getGenerationId();
|
|
||||||
if (bitmap != lastBitmap || generationId != lastBitmapGenerationId) {
|
|
||||||
lastBitmap = bitmap;
|
|
||||||
lastBitmapGenerationId = generationId;
|
|
||||||
try {
|
|
||||||
if (lastTextureId == C.INDEX_UNSET) {
|
|
||||||
lastTextureId = GlUtil.generateTexture();
|
|
||||||
}
|
|
||||||
GlUtil.setTexture(lastTextureId, bitmap);
|
|
||||||
} catch (GlUtil.GlException e) {
|
|
||||||
throw new VideoFrameProcessingException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lastTextureId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float[] getVertexTransformation(long presentationTimeUs) {
|
|
||||||
// Whereas the Android system uses the top-left corner as (0,0) of the
|
|
||||||
// coordinate system, OpenGL uses the bottom-left corner as (0,0), so the
|
|
||||||
// texture gets flipped. Flip the texture vertically to ensure the
|
|
||||||
// orientation of the output is correct.
|
|
||||||
return flipVerticallyMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link BitmapOverlay} that shows the {@code overlayBitmap} in the same position and
|
* Creates a {@link BitmapOverlay} that shows the {@code overlayBitmap} in the same position and
|
||||||
* size throughout the whole video.
|
* size throughout the whole video.
|
||||||
|
|
@ -179,6 +131,54 @@ public abstract class BitmapOverlay extends TextureOverlay {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the overlay bitmap displayed at the specified timestamp.
|
||||||
|
*
|
||||||
|
* @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
|
||||||
|
* @throws VideoFrameProcessingException If an error occurs while processing or drawing the frame.
|
||||||
|
*/
|
||||||
|
public abstract Bitmap getBitmap(long presentationTimeUs) throws VideoFrameProcessingException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*
|
||||||
|
* <p>Gets the width and height of the cached bitmap.
|
||||||
|
*
|
||||||
|
* @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Size getTextureSize(long presentationTimeUs) {
|
||||||
|
return new Size(checkNotNull(lastBitmap).getWidth(), checkNotNull(lastBitmap).getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTextureId(long presentationTimeUs) throws VideoFrameProcessingException {
|
||||||
|
Bitmap bitmap = getBitmap(presentationTimeUs);
|
||||||
|
int generationId = bitmap.getGenerationId();
|
||||||
|
if (bitmap != lastBitmap || generationId != lastBitmapGenerationId) {
|
||||||
|
lastBitmap = bitmap;
|
||||||
|
lastBitmapGenerationId = generationId;
|
||||||
|
try {
|
||||||
|
if (lastTextureId == C.INDEX_UNSET) {
|
||||||
|
lastTextureId = GlUtil.generateTexture();
|
||||||
|
}
|
||||||
|
GlUtil.setTexture(lastTextureId, bitmap);
|
||||||
|
} catch (GlUtil.GlException e) {
|
||||||
|
throw new VideoFrameProcessingException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lastTextureId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float[] getVertexTransformation(long presentationTimeUs) {
|
||||||
|
// Whereas the Android system uses the top-left corner as (0,0) of the
|
||||||
|
// coordinate system, OpenGL uses the bottom-left corner as (0,0), so the
|
||||||
|
// texture gets flipped. Flip the texture vertically to ensure the
|
||||||
|
// orientation of the output is correct.
|
||||||
|
return flipVerticallyMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void release() throws VideoFrameProcessingException {
|
public void release() throws VideoFrameProcessingException {
|
||||||
super.release();
|
super.release();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue