MStar的DVBC搜台流程。从java到C++

DVBC搜台流程

上层入口activity:

Z:\msd358_AN8.0\vendor\mstar\common\apps\MTvPlayer\src\com\mstar\tv\tvplayer\ui\tuning\ChannelTuning.java

详细看下面入口代码:            

                mTvChannelManager.setDvbcScanParam((short) symbol, modulation, frequency,frequency, (short) networkId); //设置搜台的一些参数                        mTvChannelManager.startDtvFullScan();//开始搜台

调用TvChannelManager类中的方法:

Z:\msd358_AN8.0\vendor\mstar\common\libraries\tv2\java\com\mstar\android\tv\TvChannelManager.java

    public boolean startDtvFullScan() {

        try {

            return mService.startDtvFullScan();

        } catch (RemoteException e) {

            e.printStackTrace();

        }

        return false;

}

先看一下找个mService是什么。

    private static ITvChannel mService = null;

    protected TvChannelManager() throws TvCommonException {

        if (true == TvServiceBinder.isNeedBindService()) {

            /* Use bindservice mechanism to create service. */

            ITvService srv = TvServiceBinder.getTvService();

            if (srv == null) {

                Log.e(TAG, "TvService doesn't exist!!");

                throw new TvCommonException("TvService doesn't exist.");

            }

 

            try {

                mService = srv.getTvChannel();

            } catch (RemoteException e) {

                e.printStackTrace();

            }

        } else {

            IBinder b = ServiceManager.getService(TvServiceBinder.TV_SERVICE);

 

            if (b == null) {

                Log.e(TAG, "TvService doesn't exist!!");

                throw new TvCommonException("TvService doesn't exist.");

            }

 

            try {

                mService = ITvService.Stub.asInterface(b).getTvChannel();

            } catch (RemoteException e) {

                e.printStackTrace();

            }

        }

}

主要看红色代码:从TvServiceBinder.getTvService();中获取TvService。

先判断TvServiceBinder是否绑定了TvService,如果已经绑定,那么就获取从TvService中获取TvChannelService.( mService = srv.getTvChannel();)

如果没有绑定那么就先绑定得到TvService后获取TvChannelService.               mService = ITvService.Stub.asInterface(b).getTvChannel();

这是aidl的基础知识。接着回到最先调用的mService.startDtvFullScan();

    @Override

    public boolean startDtvAutoScan() throws RemoteException {

        makeSourceDtv();

        try {

            if (DtvManager.getDvbcScanManager() != null) {

                mApiChecker.startNoResponseCheck(FuncIdList.FUNC_ID_CHANNEL_startDtvAutoScan);

                DtvManager.getDvbcScanManager().startAutoScan();

                mApiChecker.stopNoResponseCheck(FuncIdList.FUNC_ID_CHANNEL_startDtvAutoScan);

                mTuningStatus = TvChannelManager.TUNING_STATUS_DTV_AUTO_TUNING;

            }

        } catch (TvCommonException e) {

            e.printStackTrace();

            return false;

        }

        return true;

    }

我们只看最后调用的方法:

Z:\msd358_AN8.0\vendor\mstar\common\libraries\tvapi\java\com\mstar\android\tvapi\impl\ScanManagerImpl.java

public native final boolean startFullScan() throws TvCommonException;

    static {

        try {

            System.loadLibrary("scanmanagerimpl_jni");

            native_init();

        } catch (UnsatisfiedLinkError e) {

            System.err.println("Cannot load scanmanagerimpl_jni library:\n" + e.toString());

        }

    }

最后调用的是native方法startFullScan();

特别注意的是System.loadLibrary("scanmanagerimpl_jni");此行代码加载libscanmanagerimpl_jni.so库,(通过find -name “libscanmanagerimpl_jni.so”可以找到此so文件)最终调用Z:\msd358_AN8.0\vendor\mstar\common\libraries\tvapi\jni\com_mstar_android_tvapi_impl_ScanManagerImpl.cpp中的jint JNI_OnLoad(JavaVM *vm, void *reserved)方法进行方法注册,

native_init();的作用是获取方法或变量ID。

void com_mstar_android_tvapi_impl_ScanManagerImpl_native_init

(JNIEnv *env, jclass thiz) {

    ALOGI("native_init");

    jclass clazz = env->FindClass("com/mstar/android/tvapi/impl/ScanManagerImpl");

    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");

    fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative", "(Ljava/lang/Object;IIILjava/lang/Object;)V");

    fields.player = env->GetFieldID(clazz, "mScanManagerImplContext", "I");

    fields.post_event_snservicedeadth = env->GetStaticMethodID(clazz, "PostEvent_SnServiceDeadth", "(Ljava/lang/Object;II)V");

}

接着看主要方法:

jboolean com_mstar_android_tvapi_impl_ScanManagerImpl_startFullScan

(JNIEnv *env, jobject thiz) {

    ALOGI("startFullScan");

    sp<ScanManagerImpl> ms = getScanManagerImpl(env, thiz);

    if (ms == NULL) {

        JNIEXCEPTION(env, "com/mstar/android/tvapi/common/exception/TvIpcException", "can not connect to server");

        return 0;

    }

    return ms->startFullScan();

}

sp为智能指针,此段代码使用JNI、HIDL相关知识,ms->startFullScan();调用的是

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值