MediaCodec MediaCodec Class

Definition

MediaCodec class can be used to access low-level media codecs, i.e. encoder/decoder components.

[Android.Runtime.Register("android/media/MediaCodec", ApiSince=16, DoNotGenerateAcw=true)]
public sealed class MediaCodec : Java.Lang.Object
type MediaCodec = class
    inherit Object
Inheritance
MediaCodecMediaCodec
Attributes

Remarks

Android platform documentation

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Fields

BufferFlagCodecConfig BufferFlagCodecConfig

This indicated that the buffer marked as such contains codec initialization / codec specific data instead of media data.

BufferFlagEndOfStream BufferFlagEndOfStream

This signals the end of stream, i.e. no buffers will be available after this, unless of course, Flush() follows.

BufferFlagKeyFrame BufferFlagKeyFrame

This indicates that the (encoded) buffer marked as such contains the data for a key frame.

BufferFlagPartialFrame BufferFlagPartialFrame
BufferFlagSyncFrame BufferFlagSyncFrame

This indicates that the (encoded) buffer marked as such contains the data for a key frame.

ConfigureFlagEncode ConfigureFlagEncode

If this codec is to be used as an encoder, pass this flag.

CryptoModeAesCbc CryptoModeAesCbc
CryptoModeAesCtr CryptoModeAesCtr
CryptoModeUnencrypted CryptoModeUnencrypted
InfoOutputBuffersChanged InfoOutputBuffersChanged

The output buffers have changed, the client must refer to the new set of output buffers returned by GetOutputBuffers() from this point on.

InfoOutputFormatChanged InfoOutputFormatChanged

The output format has changed, subsequent data will follow the new format.

InfoTryAgainLater InfoTryAgainLater

M:Android.Media.MediaCodec.DequeueOutputBuffer(.BufferInfo,System.Int64)

ParameterKeyRequestSyncFrame ParameterKeyRequestSyncFrame

Request that the encoder produce a sync frame "soon".

ParameterKeySuspend ParameterKeySuspend

Temporarily suspend/resume encoding of input data.

ParameterKeyVideoBitrate ParameterKeyVideoBitrate

Change a video encoder's target bitrate on the fly.

VideoScalingModeScaleToFit VideoScalingModeScaleToFit

The content is scaled to the surface dimensions

VideoScalingModeScaleToFitWithCropping VideoScalingModeScaleToFitWithCropping

The content is scaled, maintaining its aspect ratio, the whole surface area is used, content may be cropped

Properties

Class Class

Returns the unique instance of Class that represents this object's class.

(Inherited from Object)
CodecInfo CodecInfo

Get the codec info.

Handle Handle

The handle to the underlying Android instance.

(Inherited from Object)
IJavaObjectEx.IsProxy IJavaObjectEx.IsProxy Inherited from Object
IJavaObjectEx.KeyHandle IJavaObjectEx.KeyHandle Inherited from Object
IJavaObjectEx.NeedsActivation IJavaObjectEx.NeedsActivation Inherited from Object
IJavaPeerable.JniManagedPeerState IJavaPeerable.JniManagedPeerState Inherited from Object
InputFormat InputFormat
JniIdentityHashCode JniIdentityHashCode Inherited from Object
JniPeerMembers JniPeerMembers
Metrics Metrics
Name Name

Get the component name.

OutputFormat OutputFormat

Call this after dequeueOutputBuffer signals a format change by returning InfoOutputFormatChanged.

PeerReference PeerReference Inherited from Object
ThresholdClass ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)
ThresholdType ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

(Inherited from Object)

Methods

Clone() Clone()

Creates and returns a copy of this Object.

(Inherited from Object)
Configure(MediaFormat, Surface, MediaCodecConfigFlags, MediaDescrambler) Configure(MediaFormat, Surface, MediaCodecConfigFlags, MediaDescrambler)
Configure(MediaFormat, Surface, MediaCrypto, MediaCodecConfigFlags) Configure(MediaFormat, Surface, MediaCrypto, MediaCodecConfigFlags)

Configures a component.

CreateByCodecName(String) CreateByCodecName(String)

If you know the exact name of the component you want to instantiate use this method to instantiate it.

CreateDecoderByType(String) CreateDecoderByType(String)

Instantiate the preferred decoder supporting input data of the given mime type.

CreateEncoderByType(String) CreateEncoderByType(String)

Instantiate the preferred encoder supporting output data of the given mime type.

CreateInputSurface() CreateInputSurface()

Requests a Surface to use as the input to an encoder, in place of input buffers.

CreatePersistentInputSurface() CreatePersistentInputSurface()
DequeueInputBuffer(Int64) DequeueInputBuffer(Int64)

Returns the index of an input buffer to be filled with valid data or -1 if no such buffer is currently available.

DequeueOutputBuffer(MediaCodec+BufferInfo, Int64) DequeueOutputBuffer(MediaCodec+BufferInfo, Int64)

Dequeue an output buffer, block at most "timeoutUs" microseconds.

Dispose() Dispose() Inherited from Object
Dispose(Boolean) Dispose(Boolean) Inherited from Object
Equals(Object) Equals(Object)

Compares this instance with the specified object and indicates if they are equal.

(Inherited from Object)
Flush() Flush()

Flush both input and output ports of the component.

GetHashCode() GetHashCode()

Returns an integer hash code for this object.

(Inherited from Object)
GetInputBuffer(Int32) GetInputBuffer(Int32)

Returns a Clear(), writable ByteBuffer object for a dequeued input buffer index to contain the input data.

GetInputBuffers() GetInputBuffers()

Retrieve the set of input buffers.

GetInputImage(Int32) GetInputImage(Int32)

Returns a writable Image object for a dequeued input buffer index to contain the raw input video frame.

GetOutputBuffer(Int32) GetOutputBuffer(Int32)

Returns a read-only ByteBuffer for a dequeued output buffer index.

GetOutputBuffers() GetOutputBuffers()

Retrieve the set of output buffers.

GetOutputFormat(Int32) GetOutputFormat(Int32)

Returns the output format for a specific output buffer.

GetOutputImage(Int32) GetOutputImage(Int32)

Returns a read-only Image object for a dequeued output buffer index that contains the raw video frame.

JavaFinalize() JavaFinalize()

Invoked when the garbage collector has detected that this instance is no longer reachable.

(Inherited from Object)
Notify() Notify()

Causes a thread which is waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

(Inherited from Object)
NotifyAll() NotifyAll()

Causes all threads which are waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

(Inherited from Object)
QueueInputBuffer(Int32, Int32, Int32, Int64, MediaCodecBufferFlags) QueueInputBuffer(Int32, Int32, Int32, Int64, MediaCodecBufferFlags)

After filling a range of the input buffer at the specified index submit it to the component.

QueueSecureInputBuffer(Int32, Int32, MediaCodec+CryptoInfo, Int64, MediaCodecBufferFlags) QueueSecureInputBuffer(Int32, Int32, MediaCodec+CryptoInfo, Int64, MediaCodecBufferFlags)

M:Android.Media.MediaCodec.QueueInputBuffer(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)

Release() Release()

Free up resources used by the codec instance.

ReleaseOutputBuffer(Int32, Boolean) ReleaseOutputBuffer(Int32, Boolean)

If you are done with a buffer, use this call to return the buffer to the codec or to render it on the output surface.

ReleaseOutputBuffer(Int32, Int64) ReleaseOutputBuffer(Int32, Int64)

If you are done with a buffer, use this call to update its surface timestamp and return it to the codec to render it on the output surface.

Reset() Reset()

Returns the codec to its initial (Uninitialized) state.

SetCallback(MediaCodec+Callback) SetCallback(MediaCodec+Callback)

Sets an asynchronous callback for actionable MediaCodec events on the default looper.

SetCallback(MediaCodec+Callback, Handler) SetCallback(MediaCodec+Callback, Handler)
SetHandle(IntPtr, JniHandleOwnership) SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetInputSurface(Surface) SetInputSurface(Surface)
SetOnFrameRenderedListener(MediaCodec+IOnFrameRenderedListener, Handler) SetOnFrameRenderedListener(MediaCodec+IOnFrameRenderedListener, Handler)
SetOutputSurface(Surface) SetOutputSurface(Surface)
SetParameters(Bundle) SetParameters(Bundle)

Communicate additional parameter changes to the component instance.

SetVideoScalingMode(VideoScalingMode) SetVideoScalingMode(VideoScalingMode)
SignalEndOfInputStream() SignalEndOfInputStream()

Signals end-of-stream on input.

Start() Start()

After successfully configuring the component, call start.

Stop() Stop()

Finish the decode/encode session, note that the codec instance remains active and ready to be Start()ed again.

ToArray<T>() ToArray<T>() Inherited from Object
ToString() ToString()

Returns a string containing a concise, human-readable description of this object.

(Inherited from Object)
UnregisterFromRuntime() UnregisterFromRuntime() Inherited from Object
Wait() Wait()

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.

(Inherited from Object)
Wait(Int64) Wait(Int64)

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

(Inherited from Object)
Wait(Int64, Int32) Wait(Int64, Int32)

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

(Inherited from Object)

Explicit Interface Implementations

IJavaObjectEx.ToLocalJniHandle() IJavaObjectEx.ToLocalJniHandle() Inherited from Object
IJavaPeerable.Disposed() IJavaPeerable.Disposed() Inherited from Object
IJavaPeerable.DisposeUnlessReferenced() IJavaPeerable.DisposeUnlessReferenced() Inherited from Object
IJavaPeerable.Finalized() IJavaPeerable.Finalized() Inherited from Object
IJavaPeerable.SetJniIdentityHashCode(Int32) IJavaPeerable.SetJniIdentityHashCode(Int32) Inherited from Object
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) Inherited from Object
IJavaPeerable.SetPeerReference(JniObjectReference) IJavaPeerable.SetPeerReference(JniObjectReference) Inherited from Object

Extension Methods

JavaCast<TResult>(IJavaObject) JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject) JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable) GetJniTypeName(IJavaPeerable)

Applies to