ffplayer——dlopen dlsym dlclose

函数说明:
http://www.cnblogs.com/Anker/p/3746802.html

DecoderVideo::initVpuCodecContext(VpuCodec** vpu_codec)
{
    c->open_codec = (VpuCodecOpenFactory) dlsym(gRkVpuLibHandle, "vpu_open_context");//dlsym通过句柄和连接符名称获取函数名或者变量名

    c->close_codec = (VpuCodecCloseFactory) dlsym(gRkVpuLibHandle, "vpu_close_context");
}
static bool getRkVpuLibHandle()
{
    if (gRkVpuLibHandle == NULL) {
        gRkVpuLibHandle = dlopen(RK_VPU_LIB, RTLD_NOW);//dlopen以指定模式打开指定的动态连接库文件,并返回一个句柄给调用进程
    }
    if (gRkVpuLibHandle == NULL) {
        ALOGD("Failed to open RK_VPU_LIB");
        return false;
    }
    if (gRkVpuLibHandle != NULL) {
        if ((VpuCodecOpenCtxFactory) dlsym(gRkVpuLibHandle, "vpu_open_context") == NULL)
            return false;
        if ((VpuCodecCloseCtxFactory) dlsym(gRkVpuLibHandle, "vpu_close_context") == NULL)
            return false;
    }
    return true;
}
tatic const char* RK_VPU_LIB = "libvpu.so";

1.通过dlopen打开动态链接库libvpu.so(由mpp生成),同时返回句柄gRkVpuLibHandle;2.通过dlsym,获得函数vpu_open_context

RTLD_LAZY 暂缓决定,等有需要时再解出符号
RTLD_NOW 立即决定,返回前解除所有未决定的符号。

猜你喜欢

转载自blog.csdn.net/u012868357/article/details/80174769
今日推荐