public abstract class

TextureOverlay

extends java.lang.Object

 java.lang.Object

↳androidx.media3.effect.TextureOverlay

Subclasses:

BitmapOverlay, TextOverlay, DrawableOverlay

Gradle dependencies

compile group: 'androidx.media3', name: 'media3-effect', version: '1.5.0-alpha01'

  • groupId: androidx.media3
  • artifactId: media3-effect
  • version: 1.5.0-alpha01

Artifact androidx.media3:media3-effect:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Creates overlays from OpenGL textures.

Summary

Constructors
publicTextureOverlay()

Methods
public voidconfigure(Size videoSize)

Set up resources for the overlay given the input video’s dimensions.

public OverlaySettingsgetOverlaySettings(long presentationTimeUs)

Returns the OverlaySettings controlling how the overlay is displayed at the specified timestamp.

public abstract intgetTextureId(long presentationTimeUs)

Returns the overlay texture identifier displayed at the specified timestamp.

public abstract SizegetTextureSize(long presentationTimeUs)

Returns the pixel width and height of the overlay texture displayed at the specified timestamp.

public float[]getVertexTransformation(long presentationTimeUs)

Returns a 4x4 OpenGL matrix, controlling how the vertices of the overlay are displayed at the specified timestamp.

public voidrelease()

Releases all resources.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public TextureOverlay()

Methods

public abstract int getTextureId(long presentationTimeUs)

Returns the overlay texture identifier displayed at the specified timestamp.

Parameters:

presentationTimeUs: The presentation timestamp of the current frame, in microseconds.

public abstract Size getTextureSize(long presentationTimeUs)

Returns the pixel width and height of the overlay texture displayed at the specified timestamp.

This method must be called after TextureOverlay.getTextureId(long).

Parameters:

presentationTimeUs: The presentation timestamp of the current frame, in microseconds.

public float[] getVertexTransformation(long presentationTimeUs)

Returns a 4x4 OpenGL matrix, controlling how the vertices of the overlay are displayed at the specified timestamp.

Applied before overlay settings.

Parameters:

presentationTimeUs: The presentation timestamp of the current frame, in microseconds.

public void configure(Size videoSize)

Set up resources for the overlay given the input video’s dimensions.

This method will be called before drawing the first frame and before drawing subsequent frames with different input dimensions.

Parameters:

videoSize: The width and height of the input video, in pixels.

public OverlaySettings getOverlaySettings(long presentationTimeUs)

Returns the OverlaySettings controlling how the overlay is displayed at the specified timestamp.

Parameters:

presentationTimeUs: The presentation timestamp of the current frame, in microseconds.

public void release()

Releases all resources.

Source

/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.media3.effect;

import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Size;
import androidx.media3.common.util.UnstableApi;

/** Creates overlays from OpenGL textures. */
@UnstableApi
public abstract class TextureOverlay {
  private static final float[] IDENTITY_MATRIX = GlUtil.create4x4IdentityMatrix();

  /**
   * Returns the overlay texture identifier 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 int getTextureId(long presentationTimeUs) throws VideoFrameProcessingException;

  // This method is required to find the size of a texture given a texture identifier using OpenGL
  // ES 2.0. OpenGL ES 3.1 can do this with glGetTexLevelParameteriv().
  /**
   * Returns the pixel width and height of the overlay texture displayed at the specified timestamp.
   *
   * <p>This method must be called after {@link #getTextureId(long)}.
   *
   * @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
   */
  public abstract Size getTextureSize(long presentationTimeUs);

  /**
   * Returns a 4x4 OpenGL matrix, controlling how the vertices of the overlay are displayed at the
   * specified timestamp.
   *
   * <p>Applied before {@linkplain #getOverlaySettings overlay settings}.
   *
   * @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
   */
  public float[] getVertexTransformation(long presentationTimeUs) {
    return IDENTITY_MATRIX;
  }

  /**
   * Set up resources for the overlay given the input video’s dimensions.
   *
   * <p>This method will be called before drawing the first frame and before drawing subsequent
   * frames with different input dimensions.
   *
   * @param videoSize The width and height of the input video, in pixels.
   */
  public void configure(Size videoSize) {}

  /**
   * Returns the {@link OverlaySettings} controlling how the overlay is displayed at the specified
   * timestamp.
   *
   * @param presentationTimeUs The presentation timestamp of the current frame, in microseconds.
   */
  public OverlaySettings getOverlaySettings(long presentationTimeUs) {
    return new OverlaySettings.Builder().build();
  }

  /**
   * Releases all resources.
   *
   * @throws VideoFrameProcessingException If an error occurs while releasing resources.
   */
  public void release() throws VideoFrameProcessingException {}
}