MediaSurfaceTexture

open class MediaSurfaceTexture(width: Int, height: Int) : OesExternalTexture

Android-specific OesExternalTexture that bridges a SurfaceTexture / Surface consumer (typically MediaPlayer, MediaCodec, or Camera2) to the WorldWind GL pipeline. The lifecycle is GL-thread-driven:

  1. Caller constructs MediaSurfaceTexture from the main thread and assigns it to a earth.worldwind.shape.ProjectedMediaSurface.texture (or any consumer that calls bindTexture).

  2. On the first render frame, super.bindTexture(dc) allocates the GL texture name; we wrap it in a SurfaceTexture + Surface and fire onSurfaceReady so the caller can hand the surface to its media producer.

  3. Each subsequent bindTexture call invokes surfaceTexture.updateTexImage() to pull the latest frame from the producer into the bound OES texture.

Context-loss recovery. When the host activity goes through pause/resume the GLSurfaceView's GL context is destroyed and rebuilt with a fresh GL name. The decoder keeps writing into the old Surface (whose backing SurfaceTexture is bound to the dead GL name), and frames silently disappear. Two recovery signals: the GL name id changing across a bind, or updateTexImage throwing because its captured EGLContext is no longer current. Either causes the wrap to be dropped; the next bind allocates a fresh SurfaceTexture + Surface and re-fires onSurfaceReady so the caller can rebind the player.

setOnFrameAvailableListener fires on the listener's caller thread by default; producer frames typically arrive on a binder / decoder thread. The listener requests a redraw (so the GL thread picks up the new frame) and then invokes the user-supplied onFrameAvailable hook for any extra wiring. Do not touch GL state from the listener — it does not run on the GL thread.

Constructors

Link copied to clipboard
constructor(width: Int, height: Int)

Properties

Link copied to clipboard
Link copied to clipboard
val coordTransform: Matrix3
Link copied to clipboard

Caller opt-out for mipmap generation.

Link copied to clipboard
val height: Int
Link copied to clipboard

Optional hook invoked after WorldWind.requestRedraw whenever the producer reports a new frame. Fires on whatever thread the producer chooses — usually a binder / decoder thread, NOT the GL thread; do not touch GL state here.

Link copied to clipboard
var onSurfaceReady: () -> Unit?

Invoked on the GL thread after surface becomes available — the first time when the GL name is initially allocated, and again after a GL context loss when the name is regenerated. The caller must hand surface to its media producer (e.g. MediaPlayer.setSurface(surface)) on each invocation; the previous Surface is no longer valid.

Link copied to clipboard

Surface wrapping the underlying SurfaceTexture. Null until onSurfaceReady fires.

Link copied to clipboard
val target: Int
Link copied to clipboard
val width: Int

Functions

Link copied to clipboard
open override fun bindTexture(dc: DrawContext): Boolean
Link copied to clipboard
fun getTexParameter(name: Int): Int
Link copied to clipboard
fun getTextureName(dc: DrawContext): KglTexture
Link copied to clipboard
open override fun release(dc: DrawContext)

Frees any resources associated with this instance. After this method returns the rendering resource is invalid, and any associated GL object is deleted.

Link copied to clipboard
fun setTexParameter(name: Int, param: Int)