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 | 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 1210 of file mediacodec_wrapper.c.
#define CREATE_DECODER_BY_TYPE 1 |
Definition at line 1211 of file mediacodec_wrapper.c.
#define CREATE_ENCODER_BY_TYPE 2 |
Definition at line 1212 of file mediacodec_wrapper.c.
#define DECLARE_FF_AMEDIACODEC_CREATE_FUNC | ( | name, | |
method | |||
) |
Definition at line 1301 of file mediacodec_wrapper.c.
#define GET_SYMBOL | ( | sym | ) |
#define DECLARE_NDK_AMEDIACODEC_CREATE_FUNC | ( | name, | |
method | |||
) |
Definition at line 2132 of file mediacodec_wrapper.c.
#define MEDIACODEC_NDK_WRAPPER | ( | method | ) |
Definition at line 2222 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 mediacodec_dec_get_video_codec(), and mediacodec_init().
char* ff_AMediaCodecList_getCodecNameByType | ( | const char * | mime, |
int | profile, | ||
int | encoder, | ||
void * | log_ctx | ||
) |
Definition at line 470 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_get_video_codec().
|
static |
Definition at line 678 of file mediacodec_wrapper.c.
|
static |
Definition at line 721 of file mediacodec_wrapper.c.
Referenced by mediacodec_jni_getOutputFormat().
|
static |
Definition at line 756 of file mediacodec_wrapper.c.
|
static |
Definition at line 778 of file mediacodec_wrapper.c.
|
static |
Definition at line 801 of file mediacodec_wrapper.c.
|
static |
Definition at line 838 of file mediacodec_wrapper.c.
|
static |
Definition at line 875 of file mediacodec_wrapper.c.
|
static |
Definition at line 912 of file mediacodec_wrapper.c.
|
static |
Definition at line 965 of file mediacodec_wrapper.c.
|
static |
Definition at line 1010 of file mediacodec_wrapper.c.
|
static |
Definition at line 1034 of file mediacodec_wrapper.c.
|
static |
Definition at line 1058 of file mediacodec_wrapper.c.
|
static |
Definition at line 1082 of file mediacodec_wrapper.c.
|
static |
Definition at line 1113 of file mediacodec_wrapper.c.
|
static |
Definition at line 1156 of file mediacodec_wrapper.c.
Referenced by codec_create().
|
inlinestatic |
Definition at line 1214 of file mediacodec_wrapper.c.
|
static |
Definition at line 1311 of file mediacodec_wrapper.c.
|
static |
Definition at line 1347 of file mediacodec_wrapper.c.
|
static |
Definition at line 1371 of file mediacodec_wrapper.c.
|
static |
Definition at line 1414 of file mediacodec_wrapper.c.
|
static |
Definition at line 1432 of file mediacodec_wrapper.c.
|
static |
Definition at line 1450 of file mediacodec_wrapper.c.
|
static |
Definition at line 1468 of file mediacodec_wrapper.c.
|
static |
Definition at line 1486 of file mediacodec_wrapper.c.
|
static |
Definition at line 1504 of file mediacodec_wrapper.c.
|
static |
Definition at line 1522 of file mediacodec_wrapper.c.
|
static |
Definition at line 1540 of file mediacodec_wrapper.c.
|
static |
Definition at line 1576 of file mediacodec_wrapper.c.
|
static |
Definition at line 1619 of file mediacodec_wrapper.c.
|
static |
Definition at line 1662 of file mediacodec_wrapper.c.
|
static |
Definition at line 1684 of file mediacodec_wrapper.c.
|
static |
Definition at line 1690 of file mediacodec_wrapper.c.
|
static |
Definition at line 1696 of file mediacodec_wrapper.c.
|
static |
Definition at line 1702 of file mediacodec_wrapper.c.
|
static |
Definition at line 1708 of file mediacodec_wrapper.c.
|
static |
Definition at line 1714 of file mediacodec_wrapper.c.
|
static |
Definition at line 1720 of file mediacodec_wrapper.c.
|
static |
Definition at line 1726 of file mediacodec_wrapper.c.
|
static |
Definition at line 1750 of file mediacodec_wrapper.c.
|
static |
Definition at line 1765 of file mediacodec_wrapper.c.
|
static |
Definition at line 1883 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_onError().
|
static |
Definition at line 1909 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_getOutputFormat(), mediacodec_ndk_onFormatChanged(), and mediaformat_ndk_new().
|
static |
Definition at line 1946 of file mediacodec_wrapper.c.
|
static |
Definition at line 1951 of file mediacodec_wrapper.c.
|
static |
Definition at line 1969 of file mediacodec_wrapper.c.
|
static |
Definition at line 1976 of file mediacodec_wrapper.c.
|
static |
Definition at line 1982 of file mediacodec_wrapper.c.
|
static |
Definition at line 1988 of file mediacodec_wrapper.c.
|
static |
Definition at line 1994 of file mediacodec_wrapper.c.
|
static |
Definition at line 2000 of file mediacodec_wrapper.c.
|
static |
Definition at line 2011 of file mediacodec_wrapper.c.
|
static |
Definition at line 2020 of file mediacodec_wrapper.c.
|
static |
Definition at line 2026 of file mediacodec_wrapper.c.
|
static |
Definition at line 2032 of file mediacodec_wrapper.c.
|
static |
Definition at line 2038 of file mediacodec_wrapper.c.
|
static |
Definition at line 2044 of file mediacodec_wrapper.c.
|
static |
Definition at line 2050 of file mediacodec_wrapper.c.
|
static |
Definition at line 2061 of file mediacodec_wrapper.c.
|
inlinestatic |
Definition at line 2081 of file mediacodec_wrapper.c.
|
static |
Definition at line 2142 of file mediacodec_wrapper.c.
|
static |
Definition at line 2163 of file mediacodec_wrapper.c.
|
static |
Definition at line 2240 of file mediacodec_wrapper.c.
|
static |
Definition at line 2246 of file mediacodec_wrapper.c.
|
static |
Definition at line 2252 of file mediacodec_wrapper.c.
|
static |
Definition at line 2258 of file mediacodec_wrapper.c.
|
static |
Definition at line 2266 of file mediacodec_wrapper.c.
|
static |
Definition at line 2281 of file mediacodec_wrapper.c.
|
static |
Definition at line 2291 of file mediacodec_wrapper.c.
|
static |
Definition at line 2305 of file mediacodec_wrapper.c.
|
static |
Definition at line 2319 of file mediacodec_wrapper.c.
|
static |
Definition at line 2324 of file mediacodec_wrapper.c.
|
static |
Definition at line 2329 of file mediacodec_wrapper.c.
|
static |
Definition at line 2334 of file mediacodec_wrapper.c.
|
static |
Definition at line 2339 of file mediacodec_wrapper.c.
|
static |
Definition at line 2344 of file mediacodec_wrapper.c.
|
static |
Definition at line 2349 of file mediacodec_wrapper.c.
|
static |
Definition at line 2354 of file mediacodec_wrapper.c.
|
static |
Definition at line 2359 of file mediacodec_wrapper.c.
|
static |
Definition at line 2379 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_setAsyncNotifyCallback().
|
static |
Definition at line 2387 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_setAsyncNotifyCallback().
|
static |
Definition at line 2404 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_setAsyncNotifyCallback().
|
static |
Definition at line 2417 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_setAsyncNotifyCallback().
|
static |
Definition at line 2429 of file mediacodec_wrapper.c.
FFAMediaFormat* ff_AMediaFormat_new | ( | int | ndk | ) |
Definition at line 2531 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 2538 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_get_video_codec(), and mediacodec_init().
FFAMediaCodec* ff_AMediaCodec_createDecoderByType | ( | const char * | mime_type, |
int | ndk | ||
) |
Definition at line 2545 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_get_audio_codec(), and mediacodec_dec_get_video_codec().
FFAMediaCodec* ff_AMediaCodec_createEncoderByType | ( | const char * | mime_type, |
int | ndk | ||
) |
Definition at line 2552 of file mediacodec_wrapper.c.
Referenced by mediacodec_init().
int ff_Build_SDK_INT | ( | AVCodecContext * | avctx | ) |
Definition at line 2559 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 2630 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_parse_video_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 2639 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 2647 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_parse_video_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 2656 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 2665 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_parse_video_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 2675 of file mediacodec_wrapper.c.
Referenced by mediacodec_dec_parse_video_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 2684 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 1868 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormat_new(), and mediaformat_ndk_create().
|
static |
Definition at line 1869 of file mediacodec_wrapper.c.
Referenced by ff_AMediaCodec_createCodecByName(), ff_AMediaCodec_createDecoderByType(), ff_AMediaCodec_createEncoderByType(), and ndk_codec_create().
|
static |
Definition at line 1871 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_configure(), and mediaformat_ndk_delete().
|
static |
Definition at line 1877 of file mediacodec_wrapper.c.
Referenced by mediacodec_ndk_delete().
enum FFAMediaFormatColorRange mf_range |
Definition at line 2593 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormatColorRange_to_AVColorRange().
enum AVColorRange range |
Definition at line 2594 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(), map_av_range(), map_range(), 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(), test_range(), 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 2601 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormatColorStandard_to_AVColorPrimaries(), and ff_AMediaFormatColorStandard_to_AVColorSpace().
enum AVColorSpace space |
Definition at line 2602 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 2612 of file mediacodec_wrapper.c.
Referenced by av_color_primaries_name(), ff_fmt_from_frame(), 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 2621 of file mediacodec_wrapper.c.
Referenced by ff_AMediaFormatColorTransfer_to_AVColorTransfer().
enum AVColorTransferCharacteristic transfer |
Definition at line 2622 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().