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

Commit 788c1053 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Enable support for capability based demux management"

parents 428c2798 a5154b3b
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -83,6 +83,22 @@ void TunerHelper::updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
    tunerRM->setFrontendInfoList(feInfos);
    tunerRM->setLnbInfoList(lnbHandles);
}
void TunerHelper::updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
                                       const vector<TunerDemuxInfo>& demuxInfos,
                                       const vector<int32_t>& lnbHandles) {
    ::ndk::SpAIBinder binder(AServiceManager_waitForService("tv_tuner_resource_mgr"));
    shared_ptr<ITunerResourceManager> tunerRM = ITunerResourceManager::fromBinder(binder);
    if (tunerRM == nullptr) {
        return;
    }

    updateTunerResources(feInfos, lnbHandles);

    // for Tuner 2.0 and below, Demux resource is not really managed under TRM
    if (demuxInfos.size() > 0) {
        tunerRM->setDemuxInfoList(demuxInfos);
    }
}

// TODO: create a map between resource id and handles.
int TunerHelper::getResourceIdFromHandle(int resourceHandle, int /*type*/) {
+6 −0
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@
#ifndef ANDROID_MEDIA_TUNERDVRHELPER_H
#define ANDROID_MEDIA_TUNERDVRHELPER_H

#include <aidl/android/media/tv/tunerresourcemanager/TunerDemuxInfo.h>
#include <aidl/android/media/tv/tunerresourcemanager/TunerFrontendInfo.h>
#include <utils/String16.h>

using ::aidl::android::media::tv::tunerresourcemanager::TunerDemuxInfo;
using ::aidl::android::media::tv::tunerresourcemanager::TunerFrontendInfo;
using ::android::String16;

@@ -55,6 +57,10 @@ public:
    // TODO: update Demux, Descrambler.
    static void updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
                                     const vector<int32_t>& lnbHandles);

    static void updateTunerResources(const vector<TunerFrontendInfo>& feInfos,
                                     const vector<TunerDemuxInfo>& demuxInfos,
                                     const vector<int32_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);
+93 −8
Original line number Diff line number Diff line
@@ -82,19 +82,76 @@ binder_status_t TunerService::instantiate() {
    return AServiceManager_addService(tunerService->asBinder().get(), getServiceName());
}

::ndk::ScopedAStatus TunerService::openDemux(int32_t /* in_demuxHandle */,
::ndk::ScopedAStatus TunerService::openDemux(int32_t in_demuxHandle,
                                             shared_ptr<ITunerDemux>* _aidl_return) {
    ALOGV("openDemux");
    vector<int32_t> id;
    shared_ptr<IDemux> demux;
    auto status = mTuner->openDemux(&id, &demux);
    bool fallBackToOpenDemux = false;
    vector<int32_t> ids;

    if (mTunerVersion <= TUNER_HAL_VERSION_2_0) {
        fallBackToOpenDemux = true;
    } else {
        mTuner->getDemuxIds(&ids);
        if (ids.size() == 0) {
            fallBackToOpenDemux = true;
        }
    }

    if (fallBackToOpenDemux) {
        auto status = mTuner->openDemux(&ids, &demux);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::UNAVAILABLE));
    } else {
        int id = TunerHelper::getResourceIdFromHandle(in_demuxHandle, DEMUX);
        auto status = mTuner->openDemuxById(id, &demux);
        if (status.isOk()) {
            *_aidl_return =
                ::ndk::SharedRefBase::make<TunerDemux>(demux, id[0], this->ref<TunerService>());
                    ::ndk::SharedRefBase::make<TunerDemux>(demux, id, this->ref<TunerService>());
        }

        return status;
    }
}

::ndk::ScopedAStatus TunerService::getDemuxInfo(int32_t in_demuxHandle, DemuxInfo* _aidl_return) {
    if (mTunerVersion <= TUNER_HAL_VERSION_2_0) {
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::UNAVAILABLE));
    }
    int id = TunerHelper::getResourceIdFromHandle(in_demuxHandle, DEMUX);
    return mTuner->getDemuxInfo(id, _aidl_return);
}

::ndk::ScopedAStatus TunerService::getDemuxInfoList(vector<DemuxInfo>* _aidl_return) {
    if (mTunerVersion <= TUNER_HAL_VERSION_2_0) {
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::UNAVAILABLE));
    }
    vector<DemuxInfo> demuxInfoList;
    vector<int32_t> ids;
    auto status = mTuner->getDemuxIds(&ids);
    if (!status.isOk()) {
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::UNAVAILABLE));
    }

    for (int i = 0; i < ids.size(); i++) {
        DemuxInfo demuxInfo;
        auto res = mTuner->getDemuxInfo(ids[i], &demuxInfo);
        if (!res.isOk()) {
            continue;
        }
        demuxInfoList.push_back(demuxInfo);
    }

    if (demuxInfoList.size() > 0) {
        *_aidl_return = demuxInfoList;
        return ::ndk::ScopedAStatus::ok();
    } else {
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::UNAVAILABLE));
    }
}

::ndk::ScopedAStatus TunerService::getDemuxCaps(DemuxCapabilities* _aidl_return) {
    ALOGV("getDemuxCaps");
@@ -230,7 +287,9 @@ void TunerService::removeSharedFilter(const shared_ptr<TunerFilter>& sharedFilte
}

void TunerService::updateTunerResources() {
    TunerHelper::updateTunerResources(getTRMFrontendInfos(), getTRMLnbHandles());
    TunerHelper::updateTunerResources(getTRMFrontendInfos(),
                                      getTRMDemuxInfos(),
                                      getTRMLnbHandles());
}

vector<TunerFrontendInfo> TunerService::getTRMFrontendInfos() {
@@ -258,6 +317,32 @@ vector<TunerFrontendInfo> TunerService::getTRMFrontendInfos() {
    return infos;
}

vector<TunerDemuxInfo> TunerService::getTRMDemuxInfos() {
    vector<TunerDemuxInfo> infos;
    vector<int32_t> ids;

    if (mTunerVersion <= TUNER_HAL_VERSION_2_0) {
        return infos;
    }

    auto status = mTuner->getDemuxIds(&ids);
    if (!status.isOk()) {
        return infos;
    }

    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)
        };
        infos.push_back(tunerDemuxInfo);
    }

    return infos;
}

vector<int32_t> TunerService::getTRMLnbHandles() {
    vector<int32_t> lnbHandles;
    if (mTuner != nullptr) {
+4 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
using ::aidl::android::hardware::tv::tuner::DemuxCapabilities;
using ::aidl::android::hardware::tv::tuner::DemuxFilterEvent;
using ::aidl::android::hardware::tv::tuner::DemuxFilterStatus;
using ::aidl::android::hardware::tv::tuner::DemuxInfo;
using ::aidl::android::hardware::tv::tuner::FrontendInfo;
using ::aidl::android::hardware::tv::tuner::FrontendType;
using ::aidl::android::hardware::tv::tuner::ITuner;
@@ -71,6 +72,8 @@ public:
    ::ndk::ScopedAStatus openDemux(int32_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 getDemuxInfoList(vector<DemuxInfo>* _aidl_return) override;
    ::ndk::ScopedAStatus openDescrambler(int32_t in_descramblerHandle,
                                         shared_ptr<ITunerDescrambler>* _aidl_return) override;
    ::ndk::ScopedAStatus getTunerHalVersion(int32_t* _aidl_return) override;
@@ -90,6 +93,7 @@ public:
private:
    void updateTunerResources();
    vector<TunerFrontendInfo> getTRMFrontendInfos();
    vector<TunerDemuxInfo> getTRMDemuxInfos();
    vector<int32_t> getTRMLnbHandles();

    shared_ptr<ITuner> mTuner;
+16 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.media.tv.tuner;

import android.hardware.tv.tuner.DemuxCapabilities;
import android.hardware.tv.tuner.DemuxInfo;
import android.hardware.tv.tuner.FrontendInfo;
import android.hardware.tv.tuner.FrontendType;
import android.media.tv.tuner.ITunerDemux;
@@ -76,6 +77,21 @@ interface ITunerService {
     */
    ITunerDemux openDemux(in int demuxHandle);

    /**
     * Retrieve the supported filter main types
     *
     * @param demuxHandle the handle of the demux to query demux info for
     * @return the demux info
     */
    DemuxInfo getDemuxInfo(in int demuxHandle);

    /**
     * Retrieve the list of demux info for all the demuxes on the system
     *
     * @return the list of DemuxInfo
     */
    DemuxInfo[] getDemuxInfoList();

    /**
     * Retrieve the Tuner Demux capabilities.
     *
Loading