1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| #include <jni.h> #include <string>
extern "C"{ #include "libavformat/avformat.h" #include "libavcodec/avcodec.h" #include "libavutil/avutil.h" #include "libavfilter/avfilter.h" }
extern "C" JNIEXPORT jstring JNICALL Java_top_luov_demo_MainActivity_stringFromJNI( JNIEnv* env, jobject ) { char str[200]; std::string hello = "Hello from C++";
av_register_all(); avcodec_version();
return env->NewStringUTF(str); }extern "C" JNIEXPORT jstring JNICALL Java_top_luov_demo_JniUtils_stringFormJNI(JNIEnv *env, jobject thiz) { return (*env).NewStringUTF("Hello from JNI ! Compiled with ABI "); } extern "C" JNIEXPORT jstring JNICALL Java_top_luov_demo_JniUtils_avformatinfo(JNIEnv *env, jobject thiz) { char info[40000] = { 0 };
av_register_all();
AVInputFormat *if_temp = av_iformat_next(NULL); AVOutputFormat *of_temp = av_oformat_next(NULL); while (if_temp != NULL) { sprintf(info, "%s[In ][%10s]\n", info, if_temp->name); if_temp = if_temp->next; } while (of_temp != NULL) { sprintf(info, "%s[Out][%10s]\n", info, of_temp->name); of_temp = of_temp->next; } return (*env).NewStringUTF(info); }
extern "C" JNIEXPORT jstring JNICALL Java_top_luov_demo_JniUtils_avcodecinfo(JNIEnv *env, jobject thiz) { char info[40000] = { 0 };
av_register_all();
AVCodec *c_temp = av_codec_next(NULL);
while (c_temp != NULL) { if (c_temp->decode != NULL) { sprintf(info, "%s[Dec]", info); } else { sprintf(info, "%s[Enc]", info); } switch (c_temp->type) { case AVMEDIA_TYPE_VIDEO: sprintf(info, "%s[Video]", info); break; case AVMEDIA_TYPE_AUDIO: sprintf(info, "%s[Audio]", info); break; default: sprintf(info, "%s[Other]", info); break; } sprintf(info, "%s[%10s]\n", info, c_temp->name);
c_temp = c_temp->next; }
return (*env).NewStringUTF(info); }
extern "C" JNIEXPORT jstring JNICALL Java_top_luov_demo_JniUtils_avfilterinfo(JNIEnv *env, jobject thiz) { char info[40000] = { 0 }; avfilter_register_all(); AVFilter *f_temp = (AVFilter *) avfilter_next(NULL); int i = 0; while (f_temp != NULL) { sprintf(info, "%s[%10s]\n", info, f_temp->name); f_temp = f_temp->next; } return (*env).NewStringUTF(info); }
extern "C" JNIEXPORT jstring JNICALL Java_top_luov_demo_JniUtils_configurationinfo(JNIEnv *env, jobject thiz) { char info[10000] = { 0 }; av_register_all();
sprintf(info, "%s\n", avcodec_configuration());
return (*env).NewStringUTF(info); }
|