Skip to content

Most visited

Recently visited

navigation

NdkMediaCodec.h File Reference

NdkMediaCodec.h File Reference

Data Structures

struct  AMediaCodecBufferInfo
 
struct  cryptoinfo_pattern_t
 

Typedefs

typedef struct ANativeWindow ANativeWindow
 
typedef struct AMediaCodec AMediaCodec
 
typedef struct AMediaCodecBufferInfo AMediaCodecBufferInfo
 
typedef struct AMediaCodecCryptoInfo AMediaCodecCryptoInfo
 

Enumerations

enum  {
  AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM = 4, AMEDIACODEC_CONFIGURE_FLAG_ENCODE = 1, AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED = -3, AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED = -2,
  AMEDIACODEC_INFO_TRY_AGAIN_LATER = -1
}
 
enum  cryptoinfo_mode_t { AMEDIACODECRYPTOINFO_MODE_CLEAR = 0, AMEDIACODECRYPTOINFO_MODE_AES_CTR = 1, AMEDIACODECRYPTOINFO_MODE_AES_WV = 2, AMEDIACODECRYPTOINFO_MODE_AES_CBC = 3 }
 

Functions

AMediaCodecAMediaCodec_createCodecByName (const char *name)
 
AMediaCodecAMediaCodec_createDecoderByType (const char *mime_type)
 
AMediaCodecAMediaCodec_createEncoderByType (const char *mime_type)
 
media_status_t AMediaCodec_delete (AMediaCodec *)
 
media_status_t AMediaCodec_configure (AMediaCodec *, const AMediaFormat *format, ANativeWindow *surface, AMediaCrypto *crypto, uint32_t flags)
 
media_status_t AMediaCodec_start (AMediaCodec *)
 
media_status_t AMediaCodec_stop (AMediaCodec *)
 
media_status_t AMediaCodec_flush (AMediaCodec *)
 
uint8_t * AMediaCodec_getInputBuffer (AMediaCodec *, size_t idx, size_t *out_size)
 
uint8_t * AMediaCodec_getOutputBuffer (AMediaCodec *, size_t idx, size_t *out_size)
 
ssize_t AMediaCodec_dequeueInputBuffer (AMediaCodec *, int64_t timeoutUs)
 
media_status_t AMediaCodec_queueInputBuffer (AMediaCodec *, size_t idx, _off_t_compat offset, size_t size, uint64_t time, uint32_t flags)
 
media_status_t AMediaCodec_queueSecureInputBuffer (AMediaCodec *, size_t idx, _off_t_compat offset, AMediaCodecCryptoInfo *, uint64_t time, uint32_t flags)
 
ssize_t AMediaCodec_dequeueOutputBuffer (AMediaCodec *, AMediaCodecBufferInfo *info, int64_t timeoutUs)
 
AMediaFormatAMediaCodec_getOutputFormat (AMediaCodec *)
 
media_status_t AMediaCodec_releaseOutputBuffer (AMediaCodec *, size_t idx, bool render)
 
media_status_t AMediaCodec_setOutputSurface (AMediaCodec *, ANativeWindow *surface)
 
media_status_t AMediaCodec_releaseOutputBufferAtTime (AMediaCodec *mData, size_t idx, int64_t timestampNs)
 
media_status_t AMediaCodec_createInputSurface (AMediaCodec *mData, ANativeWindow **surface)
 
media_status_t AMediaCodec_createPersistentInputSurface (ANativeWindow **surface)
 
media_status_t AMediaCodec_setInputSurface (AMediaCodec *mData, ANativeWindow *surface)
 
media_status_t AMediaCodec_setParameters (AMediaCodec *mData, const AMediaFormat *params)
 
media_status_t AMediaCodec_signalEndOfInputStream (AMediaCodec *mData)
 
AMediaCodecCryptoInfoAMediaCodecCryptoInfo_new (int numsubsamples, uint8_t key[16], uint8_t iv[16], cryptoinfo_mode_t mode, size_t *clearbytes, size_t *encryptedbytes)
 
media_status_t AMediaCodecCryptoInfo_delete (AMediaCodecCryptoInfo *)
 
void AMediaCodecCryptoInfo_setPattern (AMediaCodecCryptoInfo *info, cryptoinfo_pattern_t *pattern)
 
size_t AMediaCodecCryptoInfo_getNumSubSamples (AMediaCodecCryptoInfo *)
 
media_status_t AMediaCodecCryptoInfo_getKey (AMediaCodecCryptoInfo *, uint8_t *dst)
 
media_status_t AMediaCodecCryptoInfo_getIV (AMediaCodecCryptoInfo *, uint8_t *dst)
 
cryptoinfo_mode_t AMediaCodecCryptoInfo_getMode (AMediaCodecCryptoInfo *)
 
media_status_t AMediaCodecCryptoInfo_getClearBytes (AMediaCodecCryptoInfo *, size_t *dst)
 
media_status_t AMediaCodecCryptoInfo_getEncryptedBytes (AMediaCodecCryptoInfo *, size_t *dst)
 

Typedef Documentation

§ AMediaCodec

typedef struct AMediaCodec AMediaCodec

§ AMediaCodecBufferInfo

§ AMediaCodecCryptoInfo

§ ANativeWindow

typedef struct ANativeWindow ANativeWindow

Enumeration Type Documentation

§ anonymous enum

anonymous enum
Enumerator
AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM 
AMEDIACODEC_CONFIGURE_FLAG_ENCODE 
AMEDIACODEC_INFO_OUTPUT_BUFFERS_CHANGED 
AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED 
AMEDIACODEC_INFO_TRY_AGAIN_LATER 

§ cryptoinfo_mode_t

Enumerator
AMEDIACODECRYPTOINFO_MODE_CLEAR 
AMEDIACODECRYPTOINFO_MODE_AES_CTR 
AMEDIACODECRYPTOINFO_MODE_AES_WV 
AMEDIACODECRYPTOINFO_MODE_AES_CBC 

Function Documentation

§ AMediaCodec_configure()

media_status_t AMediaCodec_configure ( AMediaCodec ,
const AMediaFormat format,
ANativeWindow surface,
AMediaCrypto crypto,
uint32_t  flags 
)

Configure the codec. For decoding you would typically get the format from an extractor.

§ AMediaCodec_createCodecByName()

AMediaCodec* AMediaCodec_createCodecByName ( const char *  name)

Create codec by name. Use this if you know the exact codec you want to use. When configuring, you will need to specify whether to use the codec as an encoder or decoder.

§ AMediaCodec_createDecoderByType()

AMediaCodec* AMediaCodec_createDecoderByType ( const char *  mime_type)

Create codec by mime type. Most applications will use this, specifying a mime type obtained from media extractor.

§ AMediaCodec_createEncoderByType()

AMediaCodec* AMediaCodec_createEncoderByType ( const char *  mime_type)

Create encoder by name.

§ AMediaCodec_createInputSurface()

media_status_t AMediaCodec_createInputSurface ( AMediaCodec mData,
ANativeWindow **  surface 
)

Creates a Surface that can be used as the input to encoder, in place of input buffers

This can only be called after the codec has been configured via AMediaCodec_configure(..); and before AMediaCodec_start() has been called.

The application is responsible for releasing the surface by calling ANativeWindow_release() when done.

For more details, see the Java documentation for MediaCodec.createInputSurface.

§ AMediaCodec_createPersistentInputSurface()

media_status_t AMediaCodec_createPersistentInputSurface ( ANativeWindow **  surface)

Creates a persistent Surface that can be used as the input to encoder

Persistent surface can be reused by MediaCodec instances and can be set on a new instance via AMediaCodec_setInputSurface(). A persistent surface can be connected to at most one instance of MediaCodec at any point in time.

The application is responsible for releasing the surface by calling ANativeWindow_release() when done.

For more details, see the Java documentation for MediaCodec.createPersistentInputSurface.

§ AMediaCodec_delete()

media_status_t AMediaCodec_delete ( AMediaCodec )

delete the codec and free its resources

§ AMediaCodec_dequeueInputBuffer()

ssize_t AMediaCodec_dequeueInputBuffer ( AMediaCodec ,
int64_t  timeoutUs 
)

Get the index of the next available input buffer. An app will typically use this with getInputBuffer() to get a pointer to the buffer, then copy the data to be encoded or decoded into the buffer before passing it to the codec.

§ AMediaCodec_dequeueOutputBuffer()

ssize_t AMediaCodec_dequeueOutputBuffer ( AMediaCodec ,
AMediaCodecBufferInfo info,
int64_t  timeoutUs 
)

Get the index of the next available buffer of processed data.

§ AMediaCodec_flush()

media_status_t AMediaCodec_flush ( AMediaCodec )

§ AMediaCodec_getInputBuffer()

uint8_t* AMediaCodec_getInputBuffer ( AMediaCodec ,
size_t  idx,
size_t *  out_size 
)

Get an input buffer. The specified buffer index must have been previously obtained from dequeueInputBuffer, and not yet queued.

§ AMediaCodec_getOutputBuffer()

uint8_t* AMediaCodec_getOutputBuffer ( AMediaCodec ,
size_t  idx,
size_t *  out_size 
)

Get an output buffer. The specified buffer index must have been previously obtained from dequeueOutputBuffer, and not yet queued.

§ AMediaCodec_getOutputFormat()

AMediaFormat* AMediaCodec_getOutputFormat ( AMediaCodec )

§ AMediaCodec_queueInputBuffer()

media_status_t AMediaCodec_queueInputBuffer ( AMediaCodec ,
size_t  idx,
_off_t_compat  offset,
size_t  size,
uint64_t  time,
uint32_t  flags 
)

Send the specified buffer to the codec for processing.

§ AMediaCodec_queueSecureInputBuffer()

media_status_t AMediaCodec_queueSecureInputBuffer ( AMediaCodec ,
size_t  idx,
_off_t_compat  offset,
AMediaCodecCryptoInfo ,
uint64_t  time,
uint32_t  flags 
)

Send the specified buffer to the codec for processing.

§ AMediaCodec_releaseOutputBuffer()

media_status_t AMediaCodec_releaseOutputBuffer ( AMediaCodec ,
size_t  idx,
bool  render 
)

If you are done with a buffer, use this call to return the buffer to the codec. If you previously specified a surface when configuring this video decoder you can optionally render the buffer.

§ AMediaCodec_releaseOutputBufferAtTime()

media_status_t AMediaCodec_releaseOutputBufferAtTime ( AMediaCodec mData,
size_t  idx,
int64_t  timestampNs 
)

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. If you have not specified an output surface when configuring this video codec, this call will simply return the buffer to the codec.

For more details, see the Java documentation for MediaCodec.releaseOutputBuffer.

§ AMediaCodec_setInputSurface()

media_status_t AMediaCodec_setInputSurface ( AMediaCodec mData,
ANativeWindow surface 
)

Set a persistent-surface that can be used as the input to encoder, in place of input buffers

The surface provided must be a persistent surface created via AMediaCodec_createPersistentInputSurface() This can only be called after the codec has been configured by calling AMediaCodec_configure(..); and before AMediaCodec_start() has been called.

For more details, see the Java documentation for MediaCodec.setInputSurface.

§ AMediaCodec_setOutputSurface()

media_status_t AMediaCodec_setOutputSurface ( AMediaCodec ,
ANativeWindow surface 
)

Dynamically sets the output surface of a codec.

This can only be used if the codec was configured with an output surface. The new output surface should have a compatible usage type to the original output surface. E.g. codecs may not support switching from a SurfaceTexture (GPU readable) output to ImageReader (software readable) output.

For more details, see the Java documentation for MediaCodec.setOutputSurface.

§ AMediaCodec_setParameters()

media_status_t AMediaCodec_setParameters ( AMediaCodec mData,
const AMediaFormat params 
)

Signal additional parameters to the codec instance.

Parameters can be communicated only when the codec is running, i.e after AMediaCodec_start() has been called.

NOTE: Some of these parameter changes may silently fail to apply.

§ AMediaCodec_signalEndOfInputStream()

media_status_t AMediaCodec_signalEndOfInputStream ( AMediaCodec mData)

Signals end-of-stream on input. Equivalent to submitting an empty buffer with AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM set.

Returns AMEDIA_ERROR_INVALID_OPERATION when used with an encoder not in executing state or not receiving input from a Surface created by AMediaCodec_createInputSurface or AMediaCodec_createPersistentInputSurface.

Returns the previous codec error if one exists.

Returns AMEDIA_OK when completed succesfully.

For more details, see the Java documentation for MediaCodec.signalEndOfInputStream.

§ AMediaCodec_start()

media_status_t AMediaCodec_start ( AMediaCodec )

Start the codec. A codec must be configured before it can be started, and must be started before buffers can be sent to it.

§ AMediaCodec_stop()

media_status_t AMediaCodec_stop ( AMediaCodec )

Stop the codec.

§ AMediaCodecCryptoInfo_delete()

media_status_t AMediaCodecCryptoInfo_delete ( AMediaCodecCryptoInfo )

delete an AMediaCodecCryptoInfo created previously with AMediaCodecCryptoInfo_new, or obtained from AMediaExtractor

§ AMediaCodecCryptoInfo_getClearBytes()

media_status_t AMediaCodecCryptoInfo_getClearBytes ( AMediaCodecCryptoInfo ,
size_t *  dst 
)

The number of leading unencrypted bytes in each subsample.

§ AMediaCodecCryptoInfo_getEncryptedBytes()

media_status_t AMediaCodecCryptoInfo_getEncryptedBytes ( AMediaCodecCryptoInfo ,
size_t *  dst 
)

The number of trailing encrypted bytes in each subsample.

§ AMediaCodecCryptoInfo_getIV()

media_status_t AMediaCodecCryptoInfo_getIV ( AMediaCodecCryptoInfo ,
uint8_t *  dst 
)

A 16-byte initialization vector

§ AMediaCodecCryptoInfo_getKey()

media_status_t AMediaCodecCryptoInfo_getKey ( AMediaCodecCryptoInfo ,
uint8_t *  dst 
)

A 16-byte opaque key

§ AMediaCodecCryptoInfo_getMode()

cryptoinfo_mode_t AMediaCodecCryptoInfo_getMode ( AMediaCodecCryptoInfo )

The type of encryption that has been applied, one of AMEDIACODECRYPTOINFO_MODE_CLEAR or AMEDIACODECRYPTOINFO_MODE_AES_CTR.

§ AMediaCodecCryptoInfo_getNumSubSamples()

size_t AMediaCodecCryptoInfo_getNumSubSamples ( AMediaCodecCryptoInfo )

The number of subsamples that make up the buffer's contents.

§ AMediaCodecCryptoInfo_new()

AMediaCodecCryptoInfo* AMediaCodecCryptoInfo_new ( int  numsubsamples,
uint8_t  key[16],
uint8_t  iv[16],
cryptoinfo_mode_t  mode,
size_t *  clearbytes,
size_t *  encryptedbytes 
)

Create an AMediaCodecCryptoInfo from scratch. Use this if you need to use custom crypto info, rather than one obtained from AMediaExtractor.

AMediaCodecCryptoInfo describes the structure of an (at least partially) encrypted input sample. A buffer's data is considered to be partitioned into "subsamples", each subsample starts with a (potentially empty) run of plain, unencrypted bytes followed by a (also potentially empty) run of encrypted bytes. numBytesOfClearData can be null to indicate that all data is encrypted. This information encapsulates per-sample metadata as outlined in ISO/IEC FDIS 23001-7:2011 "Common encryption in ISO base media file format files".

§ AMediaCodecCryptoInfo_setPattern()

void AMediaCodecCryptoInfo_setPattern ( AMediaCodecCryptoInfo info,
cryptoinfo_pattern_t pattern 
)

Set the crypto pattern on an AMediaCryptoInfo object

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)