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

Commit dd8fff30 authored by Amy Zhang's avatar Amy Zhang Committed by Android (Google) Code Review
Browse files

Merge "[PARTIAL] Migrate Tuner JNI to use Client interfaces"

parents 9a09863d 9b5831b0
Loading
Loading
Loading
Loading
+272 −341

File changed.

Preview size limit exceeded, changes collapsed.

+35 −30
Original line number Diff line number Diff line
@@ -34,6 +34,11 @@
#include <utils/Mutex.h>
#include <utils/RefBase.h>

#include "tuner/DemuxClient.h"
#include "tuner/FilterClient.h"
#include "tuner/FilterClientCallback.h"
#include "tuner/FrontendClient.h"
#include "tuner/FrontendClientCallback.h"
#include "tuner/TunerClient.h"
#include "jni.h"

@@ -95,6 +100,7 @@ struct Lnb : public RefBase {
    Lnb(sp<ILnb> sp, jobject obj);
    ~Lnb();
    sp<ILnb> getILnb();
    // TODO: remove after migrate to client lib
    sp<ILnb> mLnbSp;
    jweak mLnbObj;
};
@@ -115,6 +121,7 @@ struct Dvr : public RefBase {
    jint close();
    MQ& getDvrMQ();
    sp<IDvr> getIDvr();
    // TODO: remove after migrate to client lib
    sp<IDvr> mDvrSp;
    jweak mDvrObj;
    std::unique_ptr<MQ> mDvrMQ;
@@ -123,29 +130,15 @@ struct Dvr : public RefBase {
    int mFd;
};

struct Filter : public RefBase {
    Filter(sp<IFilter> sp, jobject obj);
    ~Filter();
    int close();
    sp<IFilter> getIFilter();
    sp<IFilter> mFilterSp;
    std::unique_ptr<MQ> mFilterMQ;
    EventFlag* mFilterMQEventFlag;
    jweak mFilterObj;
    native_handle_t* mAvSharedHandle;
    uint64_t mAvSharedMemSize;
    bool mIsMediaFilter;
};

struct MediaEvent : public RefBase {
    MediaEvent(sp<Filter> filter, hidl_handle avHandle, uint64_t dataId,
    MediaEvent(sp<FilterClient> filterClient, hidl_handle avHandle, uint64_t dataId,
        uint64_t dataSize, jobject obj);
    ~MediaEvent();
    jobject getLinearBlock();
    uint64_t getAudioHandle();
    void finalize();

    sp<Filter> mFilter;
    sp<FilterClient> mFilterClient;
    native_handle_t* mAvHandle;
    uint64_t mDataId;
    uint64_t mDataSize;
@@ -159,16 +152,16 @@ struct MediaEvent : public RefBase {
    std::weak_ptr<C2Buffer> mC2Buffer;
};

struct FilterCallback : public IFilterCallback {
    ~FilterCallback();
    virtual Return<void> onFilterEvent_1_1(const DemuxFilterEvent& filterEvent,
struct FilterClientCallbackImpl : public FilterClientCallback {
    virtual void onFilterEvent_1_1(const DemuxFilterEvent& filterEvent,
            const DemuxFilterEventExt& filterEventExt);
    virtual Return<void> onFilterEvent(const DemuxFilterEvent& filterEvent);
    virtual Return<void> onFilterStatus(const DemuxFilterStatus status);
    virtual void onFilterEvent(const DemuxFilterEvent& filterEvent);
    virtual void onFilterStatus(const DemuxFilterStatus status);

    void setFilter(const sp<Filter> filter);
    void setFilter(jweak filterObj, sp<FilterClient> filterClient);
private:
    sp<Filter> mFilter;
    jweak mFilterObj;
    sp<FilterClient> mFilterClient;
    jobjectArray getSectionEvent(
            jobjectArray& arr, const std::vector<DemuxFilterEvent::Event>& events);
    jobjectArray getMediaEvent(
@@ -195,13 +188,13 @@ private:
            jobjectArray& arr, const std::vector<DemuxFilterEventExt::Event>& eventsExt);
};

struct FrontendCallback : public IFrontendCallback {
    FrontendCallback(jweak tunerObj, FrontendId id);
struct FrontendClientCallbackImpl : public FrontendClientCallback {
    FrontendClientCallbackImpl(jweak tunerObj, FrontendId id);

    virtual Return<void> onEvent(FrontendEventType frontendEventType);
    virtual Return<void> onScanMessage(
    virtual void onEvent(FrontendEventType frontendEventType);
    virtual void onScanMessage(
            FrontendScanMessageType type, const FrontendScanMessage& message);
    virtual Return<void> onScanMessageExt1_1(
    virtual void onScanMessageExt1_1(
            FrontendScanMessageTypeExt1_1 type, const FrontendScanMessageExt1_1& messageExt);

    jweak mObject;
@@ -212,22 +205,24 @@ struct TimeFilter : public RefBase {
    TimeFilter(sp<ITimeFilter> sp, jweak obj);
    ~TimeFilter();
    sp<ITimeFilter> getITimeFilter();
    // TODO: remove after migrate to client lib
    sp<ITimeFilter> mTimeFilterSp;
    jweak mTimeFilterObj;
};

struct JTuner : public RefBase {
    JTuner(JNIEnv *env, jobject thiz);
    // TODO: modify after migrate to client lib
    sp<ITuner> getTunerService();
    int getTunerVersion();
    jobject getAvSyncHwId(sp<Filter> filter);
    jobject getAvSyncHwId(sp<FilterClient> filter);
    jobject getAvSyncTime(jint id);
    int connectCiCam(jint id);
    int linkCiCam(jint id);
    int disconnectCiCam();
    int unlinkCiCam(jint id);
    jobject getFrontendIds();
    jobject openFrontendById(int id);
    jobject openFrontendByHandle(int feHandle);
    jint closeFrontendById(int id);
    jobject getFrontendInfo(int id);
    int tune(const FrontendSettings& settings, const FrontendSettingsExt1_1& settingsExt1_1);
@@ -257,15 +252,22 @@ protected:
private:
    jclass mClass;
    jweak mObject;
    // TODO: remove after migrate to client lib
    static sp<ITuner> mTuner;
    static sp<::android::hardware::tv::tuner::V1_1::ITuner> mTuner_1_1;
    static sp<TunerClient> mTunerClient;
    // TODO: remove after migrate to client lib
    sp<IFrontend> mFe;
    // TODO: remove after migrate to client lib
    sp<::android::hardware::tv::tuner::V1_1::IFrontend> mFe_1_1;
    sp<FrontendClient> mFeClient;
    int mFeId;
    hidl_vec<LnbId> mLnbIds;
    // TODO: remove after migrate to client lib
    sp<ILnb> mLnb;
    // TODO: remove after migrate to client lib
    sp<IDemux> mDemux;
    sp<DemuxClient> mDemuxClient;
    uint32_t mDemuxId;
    static jobject getAnalogFrontendCaps(JNIEnv *env, FrontendInfo::FrontendCapabilities& caps);
    static jobject getAtsc3FrontendCaps(JNIEnv *env, FrontendInfo::FrontendCapabilities& caps);
@@ -279,6 +281,9 @@ private:
    static jobject getDtmbFrontendCaps(JNIEnv *env, int id);

    bool isV1_1ExtendedStatusType(jint type);
    static uint32_t getResourceIdFromHandle(jint handle) {
        return (handle & 0x00ff0000) >> 16;
    }
};

class C2DataIdInfo : public C2Param {
+2 −4
Original line number Diff line number Diff line
@@ -68,14 +68,12 @@ sp<FilterClient> DemuxClient::openFilter(DemuxFilterType type, int bufferSize,
        sp<HidlFilterCallback> callback = new HidlFilterCallback(cb);
        sp<IFilter> hidlFilter = openHidlFilter(type, bufferSize, callback);
        if (hidlFilter != NULL) {
            sp<FilterClient> filterClient = new FilterClient();
            sp<FilterClient> filterClient = new FilterClient(type);
            filterClient->setHidlFilter(hidlFilter);
            return filterClient;
        }
    }

    // TODO: handle share av memory handle

    return NULL;
}

@@ -141,7 +139,7 @@ Result DemuxClient::disconnectCiCam() {
}

Result DemuxClient::close() {
    // pending aidl interface
    // TODO: pending aidl interface

    if (mDemux != NULL) {
        Result res = mDemux->close();
+57 −2
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@
#include "FilterClient.h"

using ::android::hardware::tv::tuner::V1_0::DemuxQueueNotifyBits;
using ::android::hardware::tv::tuner::V1_0::DemuxFilterMainType;
using ::android::hardware::tv::tuner::V1_0::DemuxMmtpFilterType;
using ::android::hardware::tv::tuner::V1_0::DemuxTsFilterType;

namespace android {

@@ -29,20 +32,25 @@ namespace android {

// TODO: pending aidl interface
// TODO: add filter callback
FilterClient::FilterClient() {
FilterClient::FilterClient(DemuxFilterType type) {
    //mTunerFilter = tunerFilter;
    mAvSharedHandle = NULL;
    checkIsMediaFilter(type);
}

FilterClient::~FilterClient() {
    //mTunerFilter = NULL;
    mFilter = NULL;
    mFilter_1_1 = NULL;
    mAvSharedHandle = NULL;
    mAvSharedMemSize = 0;
}

// TODO: remove after migration to Tuner Service is done.
void FilterClient::setHidlFilter(sp<IFilter> filter) {
    mFilter = filter;
    mFilter_1_1 = ::android::hardware::tv::tuner::V1_1::IFilter::castFrom(mFilter);
    handleAvShareMemory();
}

int FilterClient::read(uint8_t* buffer, int size) {
@@ -59,6 +67,22 @@ int FilterClient::read(uint8_t* buffer, int size) {
    return -1;
}

SharedHandleInfo FilterClient::getAvSharedHandleInfo() {
    SharedHandleInfo info{
        .sharedHandle = NULL,
        .size = 0,
    };

    // TODO: pending aidl interface

    if (mFilter_1_1 != NULL) {
        info.sharedHandle = mAvSharedHandle;
        info.size = mAvSharedMemSize;
    }

    return info;
}

Result FilterClient::configure(DemuxFilterSettings configure) {
    // TODO: pending aidl interface

@@ -187,7 +211,11 @@ Result FilterClient::close() {
    // TODO: pending aidl interface

    if (mFilter != NULL) {
        return mFilter->close();
        Result res = mFilter->close();
        if (res == Result::SUCCESS) {
            mFilter = NULL;
        }
        return res;
    }

    return Result::INVALID_STATE;
@@ -261,4 +289,31 @@ int FilterClient::copyData(uint8_t* buffer, int size) {

    return size;
}

void FilterClient::checkIsMediaFilter(DemuxFilterType type) {
    if (type.mainType == DemuxFilterMainType::MMTP) {
        if (type.subType.mmtpFilterType() == DemuxMmtpFilterType::AUDIO ||
                type.subType.mmtpFilterType() == DemuxMmtpFilterType::VIDEO) {
            mIsMediaFilter = true;
        }
    }

    if (type.mainType == DemuxFilterMainType::TS) {
        if (type.subType.tsFilterType() == DemuxTsFilterType::AUDIO ||
                type.subType.tsFilterType() == DemuxTsFilterType::VIDEO) {
            mIsMediaFilter = true;
        }
    }
}

void FilterClient::handleAvShareMemory() {
    if (mFilter_1_1 != NULL && mIsMediaFilter) {
        mFilter_1_1->getAvSharedHandle([&](Result r, hidl_handle avMemory, uint64_t avMemSize) {
            if (r == Result::SUCCESS) {
                mAvSharedHandle = native_handle_clone(avMemory.getNativeHandle());
                mAvSharedMemSize = avMemSize;
            }
        });
    }
}
}  // namespace android
+18 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_handle;
using ::android::hardware::tv::tuner::V1_0::DemuxFilterSettings;
using ::android::hardware::tv::tuner::V1_0::DemuxFilterType;
using ::android::hardware::tv::tuner::V1_0::IFilter;
using ::android::hardware::tv::tuner::V1_0::Result;
using ::android::hardware::tv::tuner::V1_1::AvStreamType;
@@ -45,6 +46,11 @@ using MQ = MessageQueue<uint8_t, kSynchronizedReadWrite>;

namespace android {

struct SharedHandleInfo {
    native_handle_t* sharedHandle;
    uint64_t size;
};

// TODO: pending aidl interface
/*class TunerFilterCallback : public BnTunerFilterCallback {

@@ -75,7 +81,7 @@ struct FilterClient : public RefBase {

public:
    // TODO: pending aidl interface
    FilterClient();
    FilterClient(DemuxFilterType type);
    ~FilterClient();

    // TODO: remove after migration to Tuner Service is done.
@@ -88,6 +94,11 @@ public:
     */
    int read(uint8_t* buffer, int size);

    /**
     * Get the a/v shared memory handle information
     */
    SharedHandleInfo getAvSharedHandleInfo();

    /**
     * Configure the filter.
     */
@@ -161,6 +172,8 @@ public:
private:
    Result getFilterMq();
    int copyData(uint8_t* buffer, int size);
    void checkIsMediaFilter(DemuxFilterType type);
    void handleAvShareMemory();

    /**
     * An AIDL Tuner Filter Singleton assigned at the first time when the Tuner Client
@@ -189,6 +202,10 @@ private:
    sp<FilterClientCallback> mCallback;
    //shared_ptr<TunerFilterCallback> mAidlCallback;
    sp<HidlFilterCallback> mHidlCallback;

    native_handle_t* mAvSharedHandle;
    uint64_t mAvSharedMemSize;
    bool mIsMediaFilter;
};
}  // namespace android