【问题标题】:Changing int main() to JNI interface prototype将 int main() 更改为 JNI 接口原型
【发布时间】:2012-03-29 01:26:42
【问题描述】:

我根据以下链接更改了ffmpeg.c

http://www.roman10.net/how-to-port-ffmpeg-the-program-to-androidideas-and-thoughts/

他说把main ()改成JNI接口原型。嗯,我对JNI接口原型不熟悉,但是看了一篇关于JNI的文章,做了相应的修改。

任何人都可以看看我的代码,看看这是不是真的?

JNIEXPORT jint JNICALL Java_com_ffmpegtest_MainActivity_main(JNIEnv *pEnv, int argc, char **argv) {
int64_t ti;

av_log_set_flags(AV_LOG_SKIP_REPEATED);

if(argc>1 && !strcmp(argv[1], "-d")){
run_as_daemon=1;
verbose=-1;
av_log_set_callback(log_callback_null);
argc--;
argv++;

}

avcodec_register_all();
#if CONFIG_AVDEVICE
avdevice_register_all();
#endif
#if CONFIG_AVFILTER
avfilter_register_all();
#endif
av_register_all();

#if HAVE_ISATTY
if(isatty(STDIN_FILENO))
avio_set_interrupt_cb(decode_interrupt_cb);
#endif

init_opts();

if(verbose>=0)
show_banner();

/* parse options */
parse_options(argc, argv, options, opt_output_file);

if(nb_output_files <= 0 && nb_input_files == 0) {
show_usage();
fprintf(stderr, "Use -h to get full help or, even better, run 'man ffmpeg'\n");
ffmpeg_exit(1);
}

/* file converter / grab */
if (nb_output_files <= 0) {
fprintf(stderr, "At least one output file must be specified\n");
ffmpeg_exit(1);
}

if (nb_input_files == 0) {
fprintf(stderr, "At least one input file must be specified\n");
ffmpeg_exit(1);
}

ti = getutime();
if (transcode(output_files, nb_output_files, input_files, nb_input_files,
stream_maps, nb_stream_maps) < 0)
ffmpeg_exit(1);
ti = getutime() - ti;
if (do_benchmark) {
int maxrss = getmaxrss() / 1024;
printf("bench: utime=%0.3fs maxrss=%ikB\n", ti / 1000000.0, maxrss);
}

return ffmpeg_exit(0);
}

【问题讨论】:

    标签: android c android-ndk ffmpeg java-native-interface


    【解决方案1】:

    应该是

    JNIEXPORT jint JNICALL 
    Java_com_ffmpegtest_MainActivity_main(JNIEnv *pEnv, jobject obj) {
    

    其中obj 是该函数所属的对象,即您的MainActivity 实例。如果您需要传递额外的参数,您还需要将它们添加到 Java 代码中的本地方法声明中。

    【讨论】:

    • 没有。如果您需要对特定点进行更多详细说明,请提出更具体的问题。
    • 好吧,我对obj的使用感到困惑。
    • obj 是包含您的 main 方法的 MainActivity 对象。
    • 我遇到了另一个问题,当我尝试编译代码时,编译器给我一个错误:'Java_com_ffmpegtest_MainActivity_main'没有以前的原型
    • @iSun 也更改头文件中的声明,或使用 javah 重新生成它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 2023-02-08
    • 2019-09-07
    • 1970-01-01
    • 2014-06-28
    相关资源
    最近更新 更多