FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
mediacodec_wrapper.c File Reference
#include <jni.h>
#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#include "libavutil/avstring.h"
#include "avcodec.h"
#include "ffjni.h"
#include "version.h"
#include "mediacodec_wrapper.h"

Go to the source code of this file.

Data Structures

struct  JNIAMediaCodecListFields
 
struct  JNIAMediaFormatFields
 
struct  FFAMediaFormat
 
struct  JNIAMediaCodecFields
 
struct  FFAMediaCodec
 

Macros

#define JNI_GET_ENV_OR_RETURN(env, log_ctx, ret)
 
#define JNI_GET_ENV_OR_RETURN_VOID(env, log_ctx)
 

Functions

int ff_AMediaCodecProfile_getProfileFromAVCodecContext (AVCodecContext *avctx)
 The following API around MediaCodec and MediaFormat is based on the NDK one provided by Google since Android 5.0. More...
 
char * ff_AMediaCodecList_getCodecNameByType (const char *mime, int profile, int encoder, void *log_ctx)
 
FFAMediaFormatff_AMediaFormat_new (void)
 
static FFAMediaFormatff_AMediaFormat_newFromObject (void *object)
 
int ff_AMediaFormat_delete (FFAMediaFormat *format)
 
char * ff_AMediaFormat_toString (FFAMediaFormat *format)
 
int ff_AMediaFormat_getInt32 (FFAMediaFormat *format, const char *name, int32_t *out)
 
int ff_AMediaFormat_getInt64 (FFAMediaFormat *format, const char *name, int64_t *out)
 
int ff_AMediaFormat_getFloat (FFAMediaFormat *format, const char *name, float *out)
 
int ff_AMediaFormat_getBuffer (FFAMediaFormat *format, const char *name, void **data, size_t *size)
 
int ff_AMediaFormat_getString (FFAMediaFormat *format, const char *name, const char **out)
 
void ff_AMediaFormat_setInt32 (FFAMediaFormat *format, const char *name, int32_t value)
 
void ff_AMediaFormat_setInt64 (FFAMediaFormat *format, const char *name, int64_t value)
 
void ff_AMediaFormat_setFloat (FFAMediaFormat *format, const char *name, float value)
 
void ff_AMediaFormat_setString (FFAMediaFormat *format, const char *name, const char *value)
 
void ff_AMediaFormat_setBuffer (FFAMediaFormat *format, const char *name, void *data, size_t size)
 
static int codec_init_static_fields (FFAMediaCodec *codec)
 
FFAMediaCodecff_AMediaCodec_createCodecByName (const char *name)
 
FFAMediaCodecff_AMediaCodec_createDecoderByType (const char *mime)
 
FFAMediaCodecff_AMediaCodec_createEncoderByType (const char *mime)
 
int ff_AMediaCodec_delete (FFAMediaCodec *codec)
 
char * ff_AMediaCodec_getName (FFAMediaCodec *codec)
 
int ff_AMediaCodec_configure (FFAMediaCodec *codec, const FFAMediaFormat *format, void *surface, void *crypto, uint32_t flags)
 
int ff_AMediaCodec_start (FFAMediaCodec *codec)
 
int ff_AMediaCodec_stop (FFAMediaCodec *codec)
 
int ff_AMediaCodec_flush (FFAMediaCodec *codec)
 
int ff_AMediaCodec_releaseOutputBuffer (FFAMediaCodec *codec, size_t idx, int render)
 
int ff_AMediaCodec_releaseOutputBufferAtTime (FFAMediaCodec *codec, size_t idx, int64_t timestampNs)
 
ssize_t ff_AMediaCodec_dequeueInputBuffer (FFAMediaCodec *codec, int64_t timeoutUs)
 
int ff_AMediaCodec_queueInputBuffer (FFAMediaCodec *codec, size_t idx, off_t offset, size_t size, uint64_t time, uint32_t flags)
 
ssize_t ff_AMediaCodec_dequeueOutputBuffer (FFAMediaCodec *codec, FFAMediaCodecBufferInfo *info, int64_t timeoutUs)
 
uint8_tff_AMediaCodec_getInputBuffer (FFAMediaCodec *codec, size_t idx, size_t *out_size)
 
uint8_tff_AMediaCodec_getOutputBuffer (FFAMediaCodec *codec, size_t idx, size_t *out_size)
 
FFAMediaFormatff_AMediaCodec_getOutputFormat (FFAMediaCodec *codec)
 
int ff_AMediaCodec_infoTryAgainLater (FFAMediaCodec *codec, ssize_t idx)
 
int ff_AMediaCodec_infoOutputBuffersChanged (FFAMediaCodec *codec, ssize_t idx)
 
int ff_AMediaCodec_infoOutputFormatChanged (FFAMediaCodec *codec, ssize_t idx)
 
int ff_AMediaCodec_getBufferFlagCodecConfig (FFAMediaCodec *codec)
 
int ff_AMediaCodec_getBufferFlagEndOfStream (FFAMediaCodec *codec)
 
int ff_AMediaCodec_getBufferFlagKeyFrame (FFAMediaCodec *codec)
 
int ff_AMediaCodec_getConfigureFlagEncode (FFAMediaCodec *codec)
 
int ff_AMediaCodec_cleanOutputBuffers (FFAMediaCodec *codec)
 

Variables

static const struct FFJniField jni_amediacodeclist_mapping []
 
static const struct FFJniField jni_amediaformat_mapping []
 
static const AVClass amediaformat_class
 
static const struct FFJniField jni_amediacodec_mapping []
 
static const AVClass amediacodec_class
 

Macro Definition Documentation

#define JNI_GET_ENV_OR_RETURN (   env,
  log_ctx,
  ret 
)
#define JNI_GET_ENV_OR_RETURN_VOID (   env,
  log_ctx 
)
Value:
do { \
(env) = ff_jni_get_env(log_ctx); \
if (!(env)) { \
} \
} while (0)
return
JNIEnv * ff_jni_get_env(void *log_ctx)
Definition: ffjni.c:51
if(ret< 0)
Definition: vf_mcdeint.c:279

Definition at line 301 of file mediacodec_wrapper.c.

Referenced by ff_AMediaFormat_setBuffer(), ff_AMediaFormat_setFloat(), ff_AMediaFormat_setInt32(), ff_AMediaFormat_setInt64(), and ff_AMediaFormat_setString().

Function Documentation

int ff_AMediaCodecProfile_getProfileFromAVCodecContext ( AVCodecContext avctx)

The following API around MediaCodec and MediaFormat is based on the NDK one provided by Google since Android 5.0.

Differences from the NDK API:

Buffers returned by ff_AMediaFormat_toString and ff_AMediaFormat_getString are newly allocated buffer and must be freed by the user after use.

The MediaCrypto API is not implemented.

ff_AMediaCodec_infoTryAgainLater, ff_AMediaCodec_infoOutputBuffersChanged, ff_AMediaCodec_infoOutputFormatChanged, ff_AMediaCodec_cleanOutputBuffers ff_AMediaCodec_getName and ff_AMediaCodec_getBufferFlagEndOfStream are not part of the original NDK API and are convenience functions to hide JNI implementation.

The API around MediaCodecList is not part of the NDK (and is lacking as we still need to retrieve the codec name to work around faulty decoders and encoders).

For documentation, please refers to NdkMediaCodec.h NdkMediaFormat.h and http://developer.android.com/reference/android/media/MediaCodec.html.

Definition at line 308 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_init().

char* ff_AMediaCodecList_getCodecNameByType ( const char *  mime,
int  profile,
int  encoder,
void log_ctx 
)

Definition at line 377 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_init().

FFAMediaFormat* ff_AMediaFormat_new ( void  )

Definition at line 607 of file mediacodec_wrapper.c.

Referenced by mediacodec_decode_init().

static FFAMediaFormat* ff_AMediaFormat_newFromObject ( void object)
static

Definition at line 652 of file mediacodec_wrapper.c.

Referenced by ff_AMediaCodec_getOutputFormat().

int ff_AMediaFormat_delete ( FFAMediaFormat format)
char* ff_AMediaFormat_toString ( FFAMediaFormat format)
int ff_AMediaFormat_getInt32 ( FFAMediaFormat format,
const char *  name,
int32_t out 
)

Definition at line 734 of file mediacodec_wrapper.c.

Referenced by mediacodec_dec_parse_format().

int ff_AMediaFormat_getInt64 ( FFAMediaFormat format,
const char *  name,
int64_t *  out 
)

Definition at line 766 of file mediacodec_wrapper.c.

int ff_AMediaFormat_getFloat ( FFAMediaFormat format,
const char *  name,
float *  out 
)

Definition at line 798 of file mediacodec_wrapper.c.

int ff_AMediaFormat_getBuffer ( FFAMediaFormat format,
const char *  name,
void **  data,
size_t *  size 
)

Definition at line 830 of file mediacodec_wrapper.c.

int ff_AMediaFormat_getString ( FFAMediaFormat format,
const char *  name,
const char **  out 
)

Definition at line 881 of file mediacodec_wrapper.c.

void ff_AMediaFormat_setInt32 ( FFAMediaFormat format,
const char *  name,
int32_t  value 
)

Definition at line 924 of file mediacodec_wrapper.c.

Referenced by mediacodec_decode_init().

void ff_AMediaFormat_setInt64 ( FFAMediaFormat format,
const char *  name,
int64_t  value 
)

Definition at line 949 of file mediacodec_wrapper.c.

void ff_AMediaFormat_setFloat ( FFAMediaFormat format,
const char *  name,
float  value 
)

Definition at line 974 of file mediacodec_wrapper.c.

void ff_AMediaFormat_setString ( FFAMediaFormat format,
const char *  name,
const char *  value 
)

Definition at line 999 of file mediacodec_wrapper.c.

Referenced by mediacodec_decode_init().

void ff_AMediaFormat_setBuffer ( FFAMediaFormat format,
const char *  name,
void data,
size_t  size 
)

Definition at line 1034 of file mediacodec_wrapper.c.

static int codec_init_static_fields ( FFAMediaCodec codec)
static
FFAMediaCodec* ff_AMediaCodec_createCodecByName ( const char *  name)

Definition at line 1135 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_init().

FFAMediaCodec* ff_AMediaCodec_createDecoderByType ( const char *  mime)

Definition at line 1200 of file mediacodec_wrapper.c.

FFAMediaCodec* ff_AMediaCodec_createEncoderByType ( const char *  mime)

Definition at line 1265 of file mediacodec_wrapper.c.

int ff_AMediaCodec_delete ( FFAMediaCodec codec)

Definition at line 1330 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_unref().

char* ff_AMediaCodec_getName ( FFAMediaCodec codec)

Definition at line 1357 of file mediacodec_wrapper.c.

int ff_AMediaCodec_configure ( FFAMediaCodec codec,
const FFAMediaFormat format,
void surface,
void crypto,
uint32_t  flags 
)

Definition at line 1376 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_init().

int ff_AMediaCodec_start ( FFAMediaCodec codec)

Definition at line 1393 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_init().

int ff_AMediaCodec_stop ( FFAMediaCodec codec)

Definition at line 1410 of file mediacodec_wrapper.c.

int ff_AMediaCodec_flush ( FFAMediaCodec codec)

Definition at line 1427 of file mediacodec_wrapper.c.

Referenced by mediacodec_dec_flush_codec().

int ff_AMediaCodec_releaseOutputBuffer ( FFAMediaCodec codec,
size_t  idx,
int  render 
)
int ff_AMediaCodec_releaseOutputBufferAtTime ( FFAMediaCodec codec,
size_t  idx,
int64_t  timestampNs 
)

Definition at line 1461 of file mediacodec_wrapper.c.

ssize_t ff_AMediaCodec_dequeueInputBuffer ( FFAMediaCodec codec,
int64_t  timeoutUs 
)

Definition at line 1478 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

int ff_AMediaCodec_queueInputBuffer ( FFAMediaCodec codec,
size_t  idx,
off_t  offset,
size_t  size,
uint64_t  time,
uint32_t  flags 
)

Definition at line 1495 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

ssize_t ff_AMediaCodec_dequeueOutputBuffer ( FFAMediaCodec codec,
FFAMediaCodecBufferInfo info,
int64_t  timeoutUs 
)

Definition at line 1512 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

uint8_t* ff_AMediaCodec_getInputBuffer ( FFAMediaCodec codec,
size_t  idx,
size_t *  out_size 
)

Definition at line 1564 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

uint8_t* ff_AMediaCodec_getOutputBuffer ( FFAMediaCodec codec,
size_t  idx,
size_t *  out_size 
)

Definition at line 1612 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

FFAMediaFormat* ff_AMediaCodec_getOutputFormat ( FFAMediaCodec codec)

Definition at line 1660 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode(), and ff_mediacodec_dec_init().

int ff_AMediaCodec_infoTryAgainLater ( FFAMediaCodec codec,
ssize_t  idx 
)

Definition at line 1683 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

int ff_AMediaCodec_infoOutputBuffersChanged ( FFAMediaCodec codec,
ssize_t  idx 
)

Definition at line 1688 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

int ff_AMediaCodec_infoOutputFormatChanged ( FFAMediaCodec codec,
ssize_t  idx 
)

Definition at line 1693 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

int ff_AMediaCodec_getBufferFlagCodecConfig ( FFAMediaCodec codec)

Definition at line 1698 of file mediacodec_wrapper.c.

int ff_AMediaCodec_getBufferFlagEndOfStream ( FFAMediaCodec codec)

Definition at line 1703 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

int ff_AMediaCodec_getBufferFlagKeyFrame ( FFAMediaCodec codec)

Definition at line 1708 of file mediacodec_wrapper.c.

int ff_AMediaCodec_getConfigureFlagEncode ( FFAMediaCodec codec)

Definition at line 1713 of file mediacodec_wrapper.c.

int ff_AMediaCodec_cleanOutputBuffers ( FFAMediaCodec codec)

Definition at line 1718 of file mediacodec_wrapper.c.

Referenced by ff_mediacodec_dec_decode().

Variable Documentation

const struct FFJniField jni_amediacodeclist_mapping[]
static

Definition at line 71 of file mediacodec_wrapper.c.

const struct FFJniField jni_amediaformat_mapping[]
static
Initial value:
= {
{ "android/media/MediaFormat", NULL, NULL, FF_JNI_CLASS, 0x42, 1 },
{ "android/media/MediaFormat", "<init>", "()V", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "getInteger", "(Ljava/lang/String;)I", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "getLong", "(Ljava/lang/String;)J", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "getFloat", "(Ljava/lang/String;)F", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "getByteBuffer", "(Ljava/lang/String;)Ljava/nio/ByteBuffer;", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "getString", "(Ljava/lang/String;)Ljava/lang/String;", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "setInteger", "(Ljava/lang/String;I)V", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "setLong", "(Ljava/lang/String;J)V", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "setFloat", "(Ljava/lang/String;F)V", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "setByteBuffer", "(Ljava/lang/String;Ljava/nio/ByteBuffer;)V", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "setString", "(Ljava/lang/String;Ljava/lang/String;)V", FF_JNI_METHOD, 0x42, 1 },
{ "android/media/MediaFormat", "toString", "()Ljava/lang/String;", FF_JNI_METHOD, 0x42, 1 },
{ NULL }
}
#define NULL
Definition: coverity.c:32

Definition at line 130 of file mediacodec_wrapper.c.

const AVClass amediaformat_class
static
Initial value:
= {
.class_name = "amediaformat",
.item_name = av_default_item_name,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:193
#define LIBAVCODEC_VERSION_INT
Definition: version.h:34

Definition at line 152 of file mediacodec_wrapper.c.

Referenced by ff_AMediaFormat_new(), and ff_AMediaFormat_newFromObject().

const struct FFJniField jni_amediacodec_mapping[]
static

Definition at line 215 of file mediacodec_wrapper.c.

const AVClass amediacodec_class
static
Initial value:
= {
.class_name = "amediacodec",
.item_name = av_default_item_name,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:193
#define LIBAVCODEC_VERSION_INT
Definition: version.h:34

Definition at line 264 of file mediacodec_wrapper.c.

Referenced by ff_AMediaCodec_createCodecByName(), ff_AMediaCodec_createDecoderByType(), and ff_AMediaCodec_createEncoderByType().