Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ea46f9c authored by Yixiao Luo's avatar Yixiao Luo Committed by Android (Google) Code Review
Browse files

Merge "ResourceHandle : Refactor resourceHandle data type to long" into main

parents aa7d9130 5338e406
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ bool TunerHelper::checkTunerFeature() {

// TODO: update Demux, Descrambler.
void TunerHelper::updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
                                       const vector<int32_t>& lnbHandles) {
                                       const vector<int64_t>& lnbHandles) {
    ::ndk::SpAIBinder binder(AServiceManager_waitForService("tv_tuner_resource_mgr"));
    shared_ptr<ITunerResourceManager> tunerRM = ITunerResourceManager::fromBinder(binder);
    if (tunerRM == nullptr) {
@@ -85,7 +85,7 @@ void TunerHelper::updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
}
void TunerHelper::updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
                                       const vector<TunerDemuxInfo>& demuxInfos,
                                       const vector<int32_t>& lnbHandles) {
                                       const vector<int64_t>& lnbHandles) {
    ::ndk::SpAIBinder binder(AServiceManager_waitForService("tv_tuner_resource_mgr"));
    shared_ptr<ITunerResourceManager> tunerRM = ITunerResourceManager::fromBinder(binder);
    if (tunerRM == nullptr) {
@@ -101,13 +101,22 @@ void TunerHelper::updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
}

// TODO: create a map between resource id and handles.
int TunerHelper::getResourceIdFromHandle(int resourceHandle, int /*type*/) {
    return (resourceHandle & 0x00ff0000) >> 16;
int TunerHelper::getResourceIdFromHandle(long resourceHandle, int /*type*/) {
    return (int)((resourceHandle >> RESOURCE_ID_SHIFT) & RESOURCE_ID_MASK);
}

int TunerHelper::getResourceHandleFromId(int id, int resourceType) {
/**
 *   Generate resource handle for resourceType and id
 *   Resource Handle Allotment : 64 bits (long)
 *   8 bits - resourceType
 *   32 bits - id
 *   24 bits - resourceRequestCount
 */
long TunerHelper::getResourceHandleFromId(int id, int resourceType) {
    // TODO: build up randomly generated id to handle mapping
    return (resourceType & 0x000000ff) << 24 | (id << 16) | (sResourceRequestCount++ & 0xffff);
    return static_cast<int64_t>(resourceType & RESOURCE_TYPE_MASK) << RESOURCE_TYPE_SHIFT |
           static_cast<int64_t>(id & RESOURCE_ID_MASK) << RESOURCE_ID_SHIFT |
           (sResourceRequestCount++ & RESOURCE_COUNT_MASK);
}

}  // namespace tuner
+10 −4
Original line number Diff line number Diff line
@@ -56,17 +56,23 @@ public:

    // TODO: update Demux, Descrambler.
    static void updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
                                     const vector<int32_t>& lnbHandles);
                                     const vector<int64_t>& lnbHandles);

    static void updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
                                     const vector<TunerDemuxInfo>& demuxInfos,
                                     const vector<int32_t>& lnbHandles);
                                     const vector<int64_t>& lnbHandles);
    // TODO: create a map between resource id and handles.
    static int getResourceIdFromHandle(int resourceHandle, int type);
    static int getResourceHandleFromId(int id, int resourceType);
    static int getResourceIdFromHandle(long resourceHandle, int type);
    static long getResourceHandleFromId(int id, int resourceType);

private:
    static int32_t sResourceRequestCount;

    static constexpr uint32_t RESOURCE_ID_SHIFT = 24;
    static constexpr uint32_t RESOURCE_TYPE_SHIFT = 56;
    static constexpr uint32_t RESOURCE_COUNT_MASK = 0xffffff;
    static constexpr uint32_t RESOURCE_ID_MASK = 0xffffffff;
    static constexpr uint32_t RESOURCE_TYPE_MASK = 0xff;
};

}  // namespace tuner
+10 −12
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ binder_status_t TunerService::instantiate() {
    return AServiceManager_addService(tunerService->asBinder().get(), getServiceName());
}

::ndk::ScopedAStatus TunerService::openDemux(int32_t in_demuxHandle,
::ndk::ScopedAStatus TunerService::openDemux(int64_t in_demuxHandle,
                                             shared_ptr<ITunerDemux>* _aidl_return) {
    ALOGV("openDemux");
    shared_ptr<IDemux> demux;
@@ -116,7 +116,7 @@ binder_status_t TunerService::instantiate() {
    }
}

::ndk::ScopedAStatus TunerService::getDemuxInfo(int32_t in_demuxHandle, DemuxInfo* _aidl_return) {
::ndk::ScopedAStatus TunerService::getDemuxInfo(int64_t in_demuxHandle, DemuxInfo* _aidl_return) {
    if (mTunerVersion <= TUNER_HAL_VERSION_2_0) {
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::UNAVAILABLE));
@@ -169,7 +169,7 @@ binder_status_t TunerService::instantiate() {
    return mTuner->getFrontendInfo(id, _aidl_return);
}

::ndk::ScopedAStatus TunerService::openFrontend(int32_t frontendHandle,
::ndk::ScopedAStatus TunerService::openFrontend(int64_t frontendHandle,
                                                shared_ptr<ITunerFrontend>* _aidl_return) {
    int id = TunerHelper::getResourceIdFromHandle(frontendHandle, FRONTEND);
    shared_ptr<IFrontend> frontend;
@@ -181,7 +181,7 @@ binder_status_t TunerService::instantiate() {
    return status;
}

::ndk::ScopedAStatus TunerService::openLnb(int lnbHandle, shared_ptr<ITunerLnb>* _aidl_return) {
::ndk::ScopedAStatus TunerService::openLnb(int64_t lnbHandle, shared_ptr<ITunerLnb>* _aidl_return) {
    shared_ptr<ILnb> lnb;
    int id = TunerHelper::getResourceIdFromHandle(lnbHandle, LNB);
    auto status = mTuner->openLnbById(id, &lnb);
@@ -204,7 +204,7 @@ binder_status_t TunerService::instantiate() {
    return ::ndk::ScopedAStatus::ok();
}

::ndk::ScopedAStatus TunerService::openDescrambler(int32_t /*descramblerHandle*/,
::ndk::ScopedAStatus TunerService::openDescrambler(int64_t /*descramblerHandle*/,
                                                   shared_ptr<ITunerDescrambler>* _aidl_return) {
    shared_ptr<IDescrambler> descrambler;
    // int id = TunerHelper::getResourceIdFromHandle(descramblerHandle, DESCRAMBLER);
@@ -310,7 +310,7 @@ vector<TunerFrontendInfo> TunerService::getTRMFrontendInfos() {
            continue;
        }
        TunerFrontendInfo tunerFrontendInfo{
                .handle = TunerHelper::getResourceHandleFromId((int)ids[i], FRONTEND),
                .handle = TunerHelper::getResourceHandleFromId(ids[i], FRONTEND),
                .type = static_cast<int>(frontendInfo.type),
                .exclusiveGroupId = frontendInfo.exclusiveGroupId,
        };
@@ -336,18 +336,16 @@ vector<TunerDemuxInfo> TunerService::getTRMDemuxInfos() {
    for (int i = 0; i < ids.size(); i++) {
        DemuxInfo demuxInfo;
        mTuner->getDemuxInfo(ids[i], &demuxInfo);
        TunerDemuxInfo tunerDemuxInfo{
                .handle = TunerHelper::getResourceHandleFromId((int)ids[i], DEMUX),
                .filterTypes = static_cast<int>(demuxInfo.filterTypes)
        };
        TunerDemuxInfo tunerDemuxInfo{.handle = TunerHelper::getResourceHandleFromId(ids[i], DEMUX),
                                      .filterTypes = static_cast<int>(demuxInfo.filterTypes)};
        infos.push_back(tunerDemuxInfo);
    }

    return infos;
}

vector<int32_t> TunerService::getTRMLnbHandles() {
    vector<int32_t> lnbHandles;
vector<int64_t> TunerService::getTRMLnbHandles() {
    vector<int64_t> lnbHandles;
    if (mTuner != nullptr) {
        vector<int32_t> lnbIds;
        auto res = mTuner->getLnbIds(&lnbIds);
+7 −7
Original line number Diff line number Diff line
@@ -61,20 +61,20 @@ public:
    virtual ~TunerService();

    ::ndk::ScopedAStatus getFrontendIds(vector<int32_t>* out_ids) override;
    ::ndk::ScopedAStatus getFrontendInfo(int32_t in_frontendHandle,
    ::ndk::ScopedAStatus getFrontendInfo(int32_t in_frontendId,
                                         FrontendInfo* _aidl_return) override;
    ::ndk::ScopedAStatus openFrontend(int32_t in_frontendHandle,
    ::ndk::ScopedAStatus openFrontend(int64_t in_frontendHandle,
                                      shared_ptr<ITunerFrontend>* _aidl_return) override;
    ::ndk::ScopedAStatus openLnb(int32_t in_lnbHandle,
    ::ndk::ScopedAStatus openLnb(int64_t in_lnbHandle,
                                 shared_ptr<ITunerLnb>* _aidl_return) override;
    ::ndk::ScopedAStatus openLnbByName(const string& in_lnbName,
                                       shared_ptr<ITunerLnb>* _aidl_return) override;
    ::ndk::ScopedAStatus openDemux(int32_t in_demuxHandle,
    ::ndk::ScopedAStatus openDemux(int64_t in_demuxHandle,
                                   shared_ptr<ITunerDemux>* _aidl_return) override;
    ::ndk::ScopedAStatus getDemuxCaps(DemuxCapabilities* _aidl_return) override;
    ::ndk::ScopedAStatus getDemuxInfo(int32_t in_demuxHandle, DemuxInfo* _aidl_return) override;
    ::ndk::ScopedAStatus getDemuxInfo(int64_t in_demuxHandle, DemuxInfo* _aidl_return) override;
    ::ndk::ScopedAStatus getDemuxInfoList(vector<DemuxInfo>* _aidl_return) override;
    ::ndk::ScopedAStatus openDescrambler(int32_t in_descramblerHandle,
    ::ndk::ScopedAStatus openDescrambler(int64_t in_descramblerHandle,
                                         shared_ptr<ITunerDescrambler>* _aidl_return) override;
    ::ndk::ScopedAStatus getTunerHalVersion(int32_t* _aidl_return) override;
    ::ndk::ScopedAStatus openSharedFilter(const string& in_filterToken,
@@ -94,7 +94,7 @@ private:
    void updateTunerResources();
    vector<TunerFrontendInfo> getTRMFrontendInfos();
    vector<TunerDemuxInfo> getTRMDemuxInfos();
    vector<int32_t> getTRMLnbHandles();
    vector<int64_t> getTRMLnbHandles();

    shared_ptr<ITuner> mTuner;
    int mTunerVersion = TUNER_HAL_VERSION_UNKNOWN;
+5 −5
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ interface ITunerService {
     * @param frontendHandle the handle of the frontend granted by TRM.
     * @return the aidl interface of the frontend.
     */
    ITunerFrontend openFrontend(in int frontendHandle);
    ITunerFrontend openFrontend(in long frontendHandle);

    /**
     * Open a new interface of ITunerLnb given a lnbHandle.
@@ -62,7 +62,7 @@ interface ITunerService {
     * @param lnbHandle the handle of the LNB granted by TRM.
     * @return a newly created ITunerLnb interface.
     */
    ITunerLnb openLnb(in int lnbHandle);
    ITunerLnb openLnb(in long lnbHandle);

    /**
     * Open a new interface of ITunerLnb given a LNB name.
@@ -75,7 +75,7 @@ interface ITunerService {
    /**
     * Create a new instance of Demux.
     */
    ITunerDemux openDemux(in int demuxHandle);
    ITunerDemux openDemux(in long demuxHandle);

    /**
     * Retrieve the supported filter main types
@@ -83,7 +83,7 @@ interface ITunerService {
     * @param demuxHandle the handle of the demux to query demux info for
     * @return the demux info
     */
    DemuxInfo getDemuxInfo(in int demuxHandle);
    DemuxInfo getDemuxInfo(in long demuxHandle);

    /**
     * Retrieve the list of demux info for all the demuxes on the system
@@ -104,7 +104,7 @@ interface ITunerService {
     * @param descramblerHandle the handle of the descrambler granted by TRM.
     * @return a newly created ITunerDescrambler interface.
     */
    ITunerDescrambler openDescrambler(in int descramblerHandle);
    ITunerDescrambler openDescrambler(in long descramblerHandle);

    /**
     * Get an integer that carries the Tuner HIDL version. The high 16 bits are the
Loading