简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长!
优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀
人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.
1.前言
本篇目的:快速查找静态注册jni的native函数通用方法
2.应用实例
1.查询setHasPreviewCallback函数对应的native函数
路径:frameworks/base/core/java/android/hardware/Camera.java
private native final void setHasPreviewCallback(boolean installed, boolean manualBuffer);
2.如何查找setHasPreviewCallback对应jni的api呢?
"jni函数名" = "路径名 + 文件名 + 函数" 组合.
查看路径最近为:android/hardware/Camera.java
所以对应的jni的函数可以写为:
android_hardware_Camera_setHasPreviewCallback
3.查找android_hardware_Camera_setHasPreviewCallback函数即可.
查找java函数setHasPreviewCallback对应到的jni的路径:frameworks/base/core/jni/android_hardware_Camera.cpp
static void android_hardware_Camera_setHasPreviewCallback(JNIEnv *env, jobject thiz, jboolean installed, jboolean manualBuffer)
{
ALOGV("setHasPreviewCallback: installed:%d, manualBuffer:%d", (int)installed, (int)manualBuffer);
// Important: Only install preview_callback if the Java code has called
// setPreviewCallback() with a non-null value, otherwise we'd pay to memcpy
// each preview frame for nothing.
JNICameraContext* context;
sp<Camera> camera = get_native_camera(env, thiz, &context);
if (camera == 0) return;
// setCallbackMode will take care of setting the context flags and calling
// camera->setPreviewCallbackFlags within a mutex for us.
context->setCallbackMode(env, installed, manualBuffer);
}
注意:如果是动态注册的jni的方法,这种方式就不奏效了。