pub struct MediaCodecFrame { /* private fields */ }Available on Android only.
Expand description
MediaCodec decoder output frame in SurfaceTexture-backed mode.
Implementations§
Source§impl MediaCodecFrame
impl MediaCodecFrame
Sourcepub unsafe fn try_from_raw(
buffer: *mut c_void,
surface_texture: *mut c_void,
format: PixelFormat,
width: u32,
height: u32,
serial: u64,
keep_alive: Option<KeepAlive>,
) -> Result<Self, InvalidHandleError>
pub unsafe fn try_from_raw( buffer: *mut c_void, surface_texture: *mut c_void, format: PixelFormat, width: u32, height: u32, serial: u64, keep_alive: Option<KeepAlive>, ) -> Result<Self, InvalidHandleError>
Wrap a MediaCodec output buffer together with the SurfaceTexture
it will be rendered into. Borrowing: the handle is stored
non-owningly, this type has no Drop, and every obligation below
extends to each Clone.
§Safety
buffermust point to a live, not yet released MediaCodec output buffer — anAVMediaCodecBuffer*from FFmpeg’smediacodechwaccel, or theAMediaCodecBufferInfo*of an NDK-dequeued output index. The import path hands it toav_mediacodec_release_buffer/AMediaCodec_releaseOutputBufferwithrender = trueto push the frame onto the surface, so a buffer that was already released is a double release. Null is rejected asInvalidHandleError::NullPointerand is not a caller obligation.- Each buffer may be wrapped once. Rendering is a one-shot
consuming act on the codec’s side; because this newtype is
Cloneand takes no ownership, two live carriers naming the samebufferwill each try to release it. surface_texturemust be a JNI global reference (not a local ref, which is invalid outside the JNI frame that made it) to theandroid.graphics.SurfaceTexturethat backs theSurfacethis codec was configured with. It is not null-checked here.width,heightandformatmust describe the frame the codec will render; the importer sizes its destination texture from them.- Thread affinity — the sharp edge.
MediaCodecFrameisSend + Sync, butSurfaceTexture.updateTexImage()is only legal on a thread with the OES texture’s GL context current, and only oneupdateTexImagemay be in flight per texture. The caller asserts the consumer will be driven from such a thread, and thatserialis monotonically increasing so the importer can detect out-of-order or repeated presentation. - Lifetime: nothing is retained and there is no
Drop. The codec, its output surface and theSurfaceTextureglobal ref must all outlive this value and everyCloneof it —keep_aliveexists to anchor them.
pub fn buffer(&self) -> *mut c_void
pub fn surface_texture(&self) -> *mut c_void
pub fn format(&self) -> PixelFormat
pub fn width(&self) -> u32
pub fn height(&self) -> u32
pub fn serial(&self) -> u64
pub fn keep_alive(&self) -> Option<&KeepAlive>
Trait Implementations§
Source§impl Clone for MediaCodecFrame
impl Clone for MediaCodecFrame
Source§impl Debug for MediaCodecFrame
impl Debug for MediaCodecFrame
impl Send for MediaCodecFrame
impl Sync for MediaCodecFrame
Auto Trait Implementations§
impl !RefUnwindSafe for MediaCodecFrame
impl !UnwindSafe for MediaCodecFrame
impl Freeze for MediaCodecFrame
impl Unpin for MediaCodecFrame
impl UnsafeUnpin for MediaCodecFrame
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more