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

Commit bca2cbe2 authored by Shubang Lu's avatar Shubang Lu Committed by Android (Google) Code Review
Browse files

Merge "TunerService: create TunerFilter and TunerDemux"

parents 6d439cd4 ae56a2e8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ cc_library {
    name: "libtunerservice",

    srcs: [
        "Tuner*.cpp"
        "Tuner*.cpp",
    ],

    shared_libs: [
+103 −0
Original line number Diff line number Diff line
/**
 * Copyright 2021, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "TunerDemux"

#include "TunerDemux.h"
#include "TunerFilter.h"

using ::android::hardware::tv::tuner::V1_0::DemuxAlpFilterType;
using ::android::hardware::tv::tuner::V1_0::DemuxFilterMainType;
using ::android::hardware::tv::tuner::V1_0::DemuxFilterType;
using ::android::hardware::tv::tuner::V1_0::DemuxIpFilterType;
using ::android::hardware::tv::tuner::V1_0::DemuxMmtpFilterType;
using ::android::hardware::tv::tuner::V1_0::DemuxTlvFilterType;
using ::android::hardware::tv::tuner::V1_0::DemuxTsFilterType;
using ::android::hardware::tv::tuner::V1_0::Result;

namespace android {

TunerDemux::TunerDemux(sp<IDemux> demux, int id) {
    mDemux = demux;
    mDemuxId = id;
}

TunerDemux::~TunerDemux() {
    mDemux = nullptr;
}

Status TunerDemux::setFrontendDataSource(const std::shared_ptr<ITunerFrontend>& frontend) {
    if (mDemux == nullptr) {
        ALOGE("IDemux is not initialized");
        return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
    }

    int frontendId;
    frontend->getFrontendId(&frontendId);
    Result res = mDemux->setFrontendDataSource(frontendId);
    if (res != Result::SUCCESS) {
        return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
    }
    return Status::ok();
}

Status TunerDemux::openFilter(
        int type, int subType, int bufferSize, const std::shared_ptr<ITunerFilterCallback>& cb,
        std::shared_ptr<ITunerFilter>* _aidl_return) {
    if (mDemux == nullptr) {
        ALOGE("IDemux is not initialized.");
        return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
    }

    DemuxFilterMainType mainType = static_cast<DemuxFilterMainType>(type);
    DemuxFilterType filterType {
        .mainType = mainType,
    };

    switch(mainType) {
        case DemuxFilterMainType::TS:
            filterType.subType.tsFilterType(static_cast<DemuxTsFilterType>(subType));
            break;
        case DemuxFilterMainType::MMTP:
            filterType.subType.mmtpFilterType(static_cast<DemuxMmtpFilterType>(subType));
            break;
        case DemuxFilterMainType::IP:
            filterType.subType.ipFilterType(static_cast<DemuxIpFilterType>(subType));
            break;
        case DemuxFilterMainType::TLV:
            filterType.subType.tlvFilterType(static_cast<DemuxTlvFilterType>(subType));
            break;
        case DemuxFilterMainType::ALP:
            filterType.subType.alpFilterType(static_cast<DemuxAlpFilterType>(subType));
            break;
    }
    Result status;
    sp<IFilter> filterSp;
    sp<IFilterCallback> cbSp = new TunerFilter::FilterCallback(cb);
    mDemux->openFilter(filterType, bufferSize, cbSp,
            [&](Result r, const sp<IFilter>& filter) {
                filterSp = filter;
                status = r;
            });
    if (status != Result::SUCCESS) {
        return Status::fromServiceSpecificError(static_cast<int32_t>(status));
    }

    *_aidl_return = ::ndk::SharedRefBase::make<TunerFilter>(filterSp, cbSp);
    return Status::ok();
}

}  // namespace android
+50 −0
Original line number Diff line number Diff line
/**
 * Copyright 2021, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_MEDIA_TUNERDEMUX_H
#define ANDROID_MEDIA_TUNERDEMUX_H

#include <aidl/android/media/tv/tuner/BnTunerDemux.h>
#include <android/hardware/tv/tuner/1.0/ITuner.h>

using Status = ::ndk::ScopedAStatus;
using ::aidl::android::media::tv::tuner::BnTunerDemux;
using ::aidl::android::media::tv::tuner::ITunerFilter;
using ::aidl::android::media::tv::tuner::ITunerFilterCallback;
using ::aidl::android::media::tv::tuner::ITunerFrontend;
using ::android::hardware::tv::tuner::V1_0::IDemux;


namespace android {

class TunerDemux : public BnTunerDemux {

public:
    TunerDemux(sp<IDemux> demux, int demuxId);
    virtual ~TunerDemux();
    Status setFrontendDataSource(const std::shared_ptr<ITunerFrontend>& frontend) override;
    Status openFilter(
        int mainType, int subtype, int bufferSize, const std::shared_ptr<ITunerFilterCallback>& cb,
        std::shared_ptr<ITunerFilter>* _aidl_return);

private:
    sp<IDemux> mDemux;
    int mDemuxId;
};

} // namespace android

#endif // ANDROID_MEDIA_TUNERDEMUX_H
+64 −0
Original line number Diff line number Diff line
/**
 * Copyright 2021, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "TunerFilter"

#include "TunerFilter.h"

using ::android::hardware::tv::tuner::V1_0::Result;

namespace android {

TunerFilter::TunerFilter(sp<IFilter> filter, sp<IFilterCallback> callback) {
    mFilter = filter;
    mFilterCallback = callback;
}

TunerFilter::~TunerFilter() {
    mFilter = nullptr;
    mFilterCallback = nullptr;
}

Status TunerFilter::getId(int32_t* _aidl_return) {
    if (mFilter == nullptr) {
        ALOGE("IFilter is not initialized");
        return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE));
    }

    Result res;
    mFilter->getId([&](Result r, uint32_t filterId) {
        res = r;
        mId = filterId;
    });
    if (res != Result::SUCCESS) {
        return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
    }
    *_aidl_return = mId;
    return Status::ok();
}

/////////////// FilterCallback ///////////////////////

Return<void> TunerFilter::FilterCallback::onFilterStatus(DemuxFilterStatus status) {
    mTunerFilterCallback->onFilterStatus((int)status);
    return Void();
}

Return<void> TunerFilter::FilterCallback::onFilterEvent(const DemuxFilterEvent&) {
    return Void();
}

}  // namespace android
+63 −0
Original line number Diff line number Diff line
/**
 * Copyright 2021, The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_MEDIA_TUNERFILTER_H
#define ANDROID_MEDIA_TUNERFILTER_H

#include <aidl/android/media/tv/tuner/BnTunerFilter.h>
#include <aidl/android/media/tv/tuner/ITunerFilterCallback.h>
#include <android/hardware/tv/tuner/1.0/ITuner.h>
#include <media/stagefright/foundation/ADebug.h>

using Status = ::ndk::ScopedAStatus;
using ::aidl::android::media::tv::tuner::BnTunerFilter;
using ::aidl::android::media::tv::tuner::ITunerFilterCallback;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::tv::tuner::V1_0::DemuxFilterEvent;
using ::android::hardware::tv::tuner::V1_0::DemuxFilterStatus;
using ::android::hardware::tv::tuner::V1_0::IFilter;
using ::android::hardware::tv::tuner::V1_0::IFilterCallback;


namespace android {

class TunerFilter : public BnTunerFilter {

public:
    TunerFilter(sp<IFilter> filter, sp<IFilterCallback> callback);
    virtual ~TunerFilter();
    Status getId(int32_t* _aidl_return) override;

    struct FilterCallback : public IFilterCallback {
        FilterCallback(const std::shared_ptr<ITunerFilterCallback> tunerFilterCallback)
                : mTunerFilterCallback(tunerFilterCallback) {};

        virtual Return<void> onFilterEvent(const DemuxFilterEvent& filterEvent);
        virtual Return<void> onFilterStatus(DemuxFilterStatus status);

        std::shared_ptr<ITunerFilterCallback> mTunerFilterCallback;
    };

private:
    sp<IFilter> mFilter;
    sp<IFilterCallback> mFilterCallback;
    int32_t mId;
};

} // namespace android

#endif // ANDROID_MEDIA_TUNERFILTER_H
Loading