FFmpeg
|
#include <dlfcn.h>
#include <jni.h>
#include <stdbool.h>
#include <media/NdkMediaFormat.h>
#include <media/NdkMediaCodec.h>
#include <android/native_window_jni.h>
#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#include "libavutil/avstring.h"
#include "avcodec.h"
#include "ffjni.h"
#include "mediacodec_wrapper.h"
Go to the source code of this file.
Data Structures | |
struct | JNIAMediaCodecListFields |
struct | JNIAMediaFormatFields |
struct | FFAMediaFormatJni |
struct | JNIAMediaCodecFields |
struct | FFAMediaCodecJni |
struct | FFAMediaFormatNdk |
struct | FFAMediaCodecNdk |
Macros | |
#define | OFFSET(x) offsetof(struct JNIAMediaCodecListFields, x) |
#define | OFFSET(x) offsetof(struct JNIAMediaFormatFields, x) |
#define | OFFSET(x) offsetof(struct JNIAMediaCodecFields, x) |
#define | JNI_GET_ENV_OR_RETURN(env, log_ctx, ret) |
#define | JNI_GET_ENV_OR_RETURN_VOID(env, log_ctx) |
#define | CREATE_CODEC_BY_NAME 0 |
#define | CREATE_DECODER_BY_TYPE 1 |
#define | CREATE_ENCODER_BY_TYPE 2 |
#define | DECLARE_FF_AMEDIACODEC_CREATE_FUNC(name, method) |
#define | GET_OPTIONAL_SYMBOL(sym) format->sym = dlsym(format->libmedia, "AMediaFormat_" #sym); |
#define | GET_SYMBOL(sym) |
#define | GET_SYMBOL(sym, required) |
#define | DECLARE_NDK_AMEDIACODEC_CREATE_FUNC(name, method) |
#define | MEDIACODEC_NDK_WRAPPER(method) |
Variables | |
static const struct FFJniField | jni_amediacodeclist_mapping [] |
static const struct FFJniField | jni_amediaformat_mapping [] |
static const AVClass | amediaformat_class |
static const FFAMediaFormat | media_format_jni |
static const struct FFJniField | jni_amediacodec_mapping [] |
static const AVClass | amediacodec_class |
static const FFAMediaCodec | media_codec_jni |
static const FFAMediaFormat | media_format_ndk |
static const FFAMediaCodec | media_codec_ndk |
static const AVClass | amediaformat_ndk_class |
static const AVClass | amediacodec_ndk_class |
struct { | |
enum FFAMediaFormatColorRange mf_range | |
enum AVColorRange range | |
} | color_range_map [] |
struct { | |
enum FFAMediaFormatColorStandard mf_standard | |
enum AVColorSpace space | |
} | color_space_map [] |
struct { | |
enum FFAMediaFormatColorStandard mf_standard | |
enum AVColorPrimaries primaries | |
} | color_primaries_map [] |
struct { | |
enum FFAMediaFormatColorTransfer mf_transfer | |
enum AVColorTransferCharacteristic transfer | |
} | color_transfer_map [] |
#define OFFSET | ( | x | ) | offsetof(struct JNIAMediaCodecListFields, x) |
Definition at line 209 of file mediacodec_wrapper.c.
#define OFFSET | ( | x | ) | offsetof(struct JNIAMediaFormatFields, x) |
Definition at line 209 of file mediacodec_wrapper.c.
#define OFFSET | ( | x | ) | offsetof(struct JNIAMediaCodecFields, x) |
Definition at line 209 of file mediacodec_wrapper.c.
#define JNI_GET_ENV_OR_RETURN | ( | env, | |
log_ctx, | |||
ret | |||
) |
Definition at line 295 of file mediacodec_wrapper.c.
#define JNI_GET_ENV_OR_RETURN_VOID | ( | env, | |
log_ctx | |||
) |
Definition at line 302 of file mediacodec_wrapper.c.
#define CREATE_CODEC_BY_NAME 0 |
Definition at line 1209 of file mediacodec_wrapper.c.
#define CREATE_DECODER_BY_TYPE 1 |
Definition at line 1210 of file mediacodec_wrapper.c.
#define CREATE_ENCODER_BY_TYPE 2 |
Definition at line 1211 of file mediacodec_wrapper.c.
#define DECLARE_FF_AMEDIACODEC_CREATE_FUNC | ( | name, | |
method | |||
) |
Definition at line 1300 of file mediacodec_wrapper.c.
#define GET_SYMBOL | ( | sym | ) |
#define GET_SYMBOL | ( | sym, | |
required | |||
) |
#define DECLARE_NDK_AMEDIACODEC_CREATE_FUNC | ( | name, | |
method | |||
) |
Definition at line 2184 of file mediacodec_wrapper.c.
#define MEDIACODEC_NDK_WRAPPER | ( | method | ) |
Definition at line 2274 of file mediacodec_wrapper.c.
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 309 of file mediacodec_wrapper.c.
Referenced by ff_mediacodec_dec_init(), and mediacodec_init().
char* ff_AMediaCodecList_getCodecNameByType | ( | const char * | mime, |
int | profile, | ||
int | encoder, | ||
void * | log_ctx | ||
) |
Definition at line 469 of file mediacodec_wrapper.c.
Referenced by ff_mediacodec_dec_init().
|
static |
Definition at line 677 of file mediacodec_wrapper.c.
|
static |
Definition at line 720 of file mediacodec_wrapper.c.
Referenced by mediacodec_jni_getOutputFormat().
|
static |
Definition at line 755 of file mediacodec_wrapper.c.
|
static |
Definition at line 777 of file mediacodec_wrapper.c.
|
static |
Definition at line 800 of file mediacodec_wrapper.c.
|
static |
Definition at line 837 of file mediacodec_wrapper.c.
|
static |
Definition at line 874 of file mediacodec_wrapper.c.
|
static |
Definition at line 911 of file mediacodec_wrapper.c.
|
static |
Definition at line 964 of file mediacodec_wrapper.c.
|
static |
Definition at line 1009 of file mediacodec_wrapper.c.
|
static |
Definition at line 1033 of file mediacodec_wrapper.c.
|
static |
Definition at line 1057 of file mediacodec_wrapper.c.
|
static |
Definition at line 1081 of file mediacodec_wrapper.c.
|
static |
Definition at line 1112 of file mediacodec_wrapper.c.
|
static |
Definition at line 1155 of file mediacodec_wrapper.c.
Referenced by codec_create().
|
inlinestatic |
Definition at line 1213 of file mediacodec_wrapper.c.
|
static |
Definition at line 1310 of file mediacodec_wrapper.c.
|
static |
Definition at line 1346 of file mediacodec_wrapper.c.
|
static |
Definition at line 1370 of file mediacodec_wrapper.c.
|
static |
Definition at line 1413 of file mediacodec_wrapper.c.
|
static |
Definition at line 1431 of file mediacodec_wrapper.c.
|
static |
Definition at line 1449 of file mediacodec_wrapper.c.
|
static |
Definition at line 1467 of file mediacodec_wrapper.c.
|
static |
Definition at line 1485 of file mediacodec_wrapper.c.
|
static |
Definition at line 1503 of file mediacodec_wrapper.c.
|
static |
Definition at line 1521 of file mediacodec_wrapper.c.
|
static |
Definition at line 1539 of file mediacodec_wrapper.c.
|
static |
Definition at line 1575 of file mediacodec_wrapper.c.
|
static |
Definition at line 1618 of file mediacodec_wrapper.c.
|
static |
Definition at line 1661 of file mediacodec_wrapper.c.
|
static |
Definition at line 1683 of file mediacodec_wrapper.c.
|
static |
Definition at line 1689 of file mediacodec_wrapper.c.
|
static |
Definition at line 1695 of file mediacodec_wrapper.c.
|
static |
Definition at line 1701 of file mediacodec_wrapper.c.
|
static |
Definition at line 1707 of file mediacodec_wrapper.c.
|
static |
Definition at line 1713 of file mediacodec_wrapper.c.
|
static |
Definition at line 1719 of file mediacodec_wrapper.c.
|
static |
Definition at line 1725 of file mediacodec_wrapper.c.
|
static |
Definition at line 1749 of file mediacodec_wrapper.c.
|
static |
Definition at line 1913 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_getOutputFormat(), and mediaformat_ndk_new().
|
static |
Definition at line 1973 of file mediacodec_wrapper.c.
|
static |
Definition at line 1978 of file mediacodec_wrapper.c.
|
static |
Definition at line 1996 of file mediacodec_wrapper.c.
|
static |
Definition at line 2003 of file mediacodec_wrapper.c.
|
static |
Definition at line 2009 of file mediacodec_wrapper.c.
|
static |
Definition at line 2015 of file mediacodec_wrapper.c.
|
static |
Definition at line 2021 of file mediacodec_wrapper.c.
|
static |
Definition at line 2027 of file mediacodec_wrapper.c.
|
static |
Definition at line 2038 of file mediacodec_wrapper.c.
|
static |
Definition at line 2047 of file mediacodec_wrapper.c.
|
static |
Definition at line 2053 of file mediacodec_wrapper.c.
|
static |
Definition at line 2059 of file mediacodec_wrapper.c.
|
static |
Definition at line 2065 of file mediacodec_wrapper.c.
|
static |
Definition at line 2071 of file mediacodec_wrapper.c.
|
static |
Definition at line 2077 of file mediacodec_wrapper.c.
|
static |
Definition at line 2088 of file mediacodec_wrapper.c.
|
inlinestatic |
Definition at line 2108 of file mediacodec_wrapper.c.
|
static |
Definition at line 2194 of file mediacodec_wrapper.c.
|
static |
Definition at line 2215 of file mediacodec_wrapper.c.
|
static |
Definition at line 2292 of file mediacodec_wrapper.c.
|
static |
Definition at line 2298 of file mediacodec_wrapper.c.
|
static |
Definition at line 2304 of file mediacodec_wrapper.c.
|
static |
Definition at line 2310 of file mediacodec_wrapper.c.
|
static |
Definition at line 2318 of file mediacodec_wrapper.c.
|
static |
Definition at line 2333 of file mediacodec_wrapper.c.
|
static |
Definition at line 2343 of file mediacodec_wrapper.c.
|
static |
Definition at line 2357 of file mediacodec_wrapper.c.
|
static |
Definition at line 2371 of file mediacodec_wrapper.c.
|
static |
Definition at line 2376 of file mediacodec_wrapper.c.
|
static |
Definition at line 2381 of file mediacodec_wrapper.c.
|
static |
Definition at line 2386 of file mediacodec_wrapper.c.
|
static |
Definition at line 2391 of file mediacodec_wrapper.c.
|
static |
Definition at line 2396 of file mediacodec_wrapper.c.
|
static |
Definition at line 2401 of file mediacodec_wrapper.c.
|
static |
Definition at line 2406 of file mediacodec_wrapper.c.
|
static |
Definition at line 2411 of file mediacodec_wrapper.c.
FFAMediaFormat* ff_AMediaFormat_new | ( | int | ndk | ) |
Definition at line 2494 of file mediacodec_wrapper.c.
Referenced by mediacodec_decode_init(), and mediacodec_init().
FFAMediaCodec* ff_AMediaCodec_createCodecByName | ( | const char * | name, |
int | ndk | ||
) |
Definition at line 2501 of file mediacodec_wrapper.c.
Referenced by ff_mediacodec_dec_init(), and mediacodec_init().
FFAMediaCodec* ff_AMediaCodec_createDecoderByType | ( | const char * | mime_type, |
int | ndk | ||
) |
Definition at line 2508 of file mediacodec_wrapper.c.
Referenced by ff_mediacodec_dec_init().
FFAMediaCodec* ff_AMediaCodec_createEncoderByType | ( | const char * | mime_type, |
int | ndk | ||
) |
Definition at line 2515 of file mediacodec_wrapper.c.
Referenced by mediacodec_init().
int ff_Build_SDK_INT | ( | AVCodecContext * | avctx | ) |
Definition at line 2522 of file mediacodec_wrapper.c.
Referenced by mediacodec_decode_init().
enum AVColorRange ff_AMediaFormatColorRange_to_AVColorRange | ( | int | color_range | ) |
Map MediaFormat color range to AVColorRange.
return AVCOL_RANGE_UNSPECIFIED when failed.
Definition at line 2593 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_parse_format().
int ff_AMediaFormatColorRange_from_AVColorRange | ( | enum AVColorRange | color_range | ) |
Map AVColorRange to MediaFormat color range.
return COLOR_RANGE_UNSPECIFIED when failed.
Definition at line 2602 of file mediacodec_wrapper.c.
Referenced by mediacodec_init().
enum AVColorSpace ff_AMediaFormatColorStandard_to_AVColorSpace | ( | int | color_standard | ) |
Map MediaFormat color standard to AVColorSpace.
return AVCOL_SPC_UNSPECIFIED when failed.
Definition at line 2610 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_parse_format().
int ff_AMediaFormatColorStandard_from_AVColorSpace | ( | enum AVColorSpace | color_space | ) |
Map AVColorSpace to MediaFormat color standard.
return COLOR_STANDARD_UNSPECIFIED when failed.
Definition at line 2619 of file mediacodec_wrapper.c.
Referenced by mediacodec_init().
enum AVColorPrimaries ff_AMediaFormatColorStandard_to_AVColorPrimaries | ( | int | color_standard | ) |
Map MediaFormat color standard to AVColorPrimaries.
return AVCOL_PRI_UNSPECIFIED when failed.
Definition at line 2628 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_parse_format().
enum AVColorTransferCharacteristic ff_AMediaFormatColorTransfer_to_AVColorTransfer | ( | int | color_transfer | ) |
Map MediaFormat color transfer to AVColorTransferCharacteristic.
return AVCOL_TRC_UNSPECIFIED when failed.
Definition at line 2638 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_parse_format().
int ff_AMediaFormatColorTransfer_from_AVColorTransfer | ( | enum AVColorTransferCharacteristic | color_transfer | ) |
Map AVColorTransferCharacteristic to MediaFormat color transfer.
return COLOR_TRANSFER_UNSPECIFIED when failed.
Definition at line 2647 of file mediacodec_wrapper.c.
Referenced by mediacodec_init().
|
static |
Definition at line 64 of file mediacodec_wrapper.c.
Referenced by ff_AMediaCodecList_getCodecNameByType().
|
static |
Definition at line 116 of file mediacodec_wrapper.c.
Referenced by ff_AMediaCodecList_getCodecNameByType(), mediaformat_jni_delete(), mediaformat_jni_new(), and mediaformat_jni_newFromObject().
|
static |
Definition at line 141 of file mediacodec_wrapper.c.
|
static |
Definition at line 154 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormat_new(), mediaformat_jni_new(), and mediaformat_jni_newFromObject().
|
static |
Definition at line 210 of file mediacodec_wrapper.c.
Referenced by codec_create(), and mediacodec_jni_delete().
|
static |
Definition at line 263 of file mediacodec_wrapper.c.
|
static |
Definition at line 293 of file mediacodec_wrapper.c.
Referenced by codec_create(), ff_AMediaCodec_createCodecByName(), ff_AMediaCodec_createDecoderByType(), and ff_AMediaCodec_createEncoderByType().
|
static |
Definition at line 1898 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormat_new(), and mediaformat_ndk_create().
|
static |
Definition at line 1899 of file mediacodec_wrapper.c.
Referenced by ff_AMediaCodec_createCodecByName(), ff_AMediaCodec_createDecoderByType(), ff_AMediaCodec_createEncoderByType(), and ndk_codec_create().
|
static |
Definition at line 1901 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_configure(), and mediaformat_ndk_delete().
|
static |
Definition at line 1907 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_delete().
enum FFAMediaFormatColorRange mf_range |
Definition at line 2556 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormatColorRange_to_AVColorRange().
enum AVColorRange range |
Definition at line 2557 of file mediacodec_wrapper.c.
Referenced by ac_normalize(), adpcm_compress_trellis(), aptx_process_subband(), arith2_get_number(), arith2_get_prob(), arith2_get_scaled_value(), arith2_rescale_interval(), arith_get_bits(), arith_get_number(), arith_get_prob(), av_color_range_name(), av_image_fill_black(), av_opt_freep_ranges(), av_opt_query_ranges_default(), aw_pulse_set2(), block_matching_multi(), calc_input_response(), calculate_mask_curve(), check_image_fill_black(), compute_kernel(), config_input(), configure_video_device(), decode_audio_block(), decode_channel(), dirac_get_arith_bit(), draw_legend(), dshow_cycle_formats(), encode_q_branch(), extend_code(), fade_gain(), ff_all_color_ranges(), ff_AMediaFormatColorRange_from_AVColorRange(), ff_bgmc_decode(), ff_draw_init2(), ff_fix_long_mvs(), ff_fix_long_p_mvs(), ff_get_best_fcode(), ff_h263_encode_motion(), ffat_init_encoder(), filter_channels(), find_image_range(), floor_encode(), floor_fit(), format_init(), g722_encode_trellis(), generate_scaling(), get_cabac_bypass(), get_cabac_bypass_sign(), get_cv_pixel_format(), get_Fragment(), get_limits(), get_te0_golomb(), get_te_golomb(), mclms_update(), msmpeg4v2_encode_motion(), opus_rc_tell_frac(), output_gain(), parse_fmtp(), plot_channel_log(), process_callback(), put_rac(), range_map(), set_te_golomb(), step_collect_psy_metrics(), sws_printVec2(), update_input_arguments(), vorbis_floor1_decode(), vt_format_from_pixfmt(), x8_setup_spatial_compensation(), and x8_setup_spatial_predictor().
struct { ... } color_range_map[] |
Referenced by ff_AMediaFormatColorRange_from_AVColorRange(), and ff_AMediaFormatColorRange_to_AVColorRange().
enum FFAMediaFormatColorStandard mf_standard |
Definition at line 2564 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormatColorStandard_to_AVColorPrimaries(), and ff_AMediaFormatColorStandard_to_AVColorSpace().
enum AVColorSpace space |
Definition at line 2565 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormatColorStandard_from_AVColorSpace().
struct { ... } color_space_map[] |
Referenced by ff_AMediaFormatColorStandard_from_AVColorSpace(), and ff_AMediaFormatColorStandard_to_AVColorSpace().
enum AVColorPrimaries primaries |
Definition at line 2575 of file mediacodec_wrapper.c.
Referenced by av_color_primaries_name(), ff_jpegxl_parse_codestream_header(), and format_init().
struct { ... } color_primaries_map[] |
Referenced by ff_AMediaFormatColorStandard_to_AVColorPrimaries().
enum FFAMediaFormatColorTransfer mf_transfer |
Definition at line 2584 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormatColorTransfer_to_AVColorTransfer().
enum AVColorTransferCharacteristic transfer |
Definition at line 2585 of file mediacodec_wrapper.c.
Referenced by av_color_transfer_name(), ff_AMediaFormatColorTransfer_from_AVColorTransfer(), and format_init().
struct { ... } color_transfer_map[] |
Referenced by ff_AMediaFormatColorTransfer_from_AVColorTransfer(), and ff_AMediaFormatColorTransfer_to_AVColorTransfer().