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

Commit e423acd4 authored by Hongguang's avatar Hongguang
Browse files

Update tuner default AIDL HAL.

*) Use tuner AIDL HAL return values.
*) Replace mTunerService with mTuner to avoid confusing.
*) Merge other HIDL HAL changes.
   *) ag/15371813, ag/15371814 and ag/15371815.

Bug: 191825295
Test: make and run VtsHalTvTunerTargetTest
Change-Id: Ibbf94c4fc36c3bda94a7e0f3e0697c83ac414d0e
parent 84d45ee9
Loading
Loading
Loading
Loading
+36 −21
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define LOG_TAG "android.hardware.tv.tuner-service.example-Demux"

#include <aidl/android/hardware/tv/tuner/DemuxQueueNotifyBits.h>
#include <aidl/android/hardware/tv/tuner/Result.h>

#include <utils/Log.h>
#include "Demux.h"
@@ -32,7 +33,7 @@ namespace tuner {

Demux::Demux(int32_t demuxId, std::shared_ptr<Tuner> tuner) {
    mDemuxId = demuxId;
    mTunerService = tuner;
    mTuner = tuner;
}

Demux::~Demux() {
@@ -43,17 +44,18 @@ Demux::~Demux() {
::ndk::ScopedAStatus Demux::setFrontendDataSource(int32_t in_frontendId) {
    ALOGV("%s", __FUNCTION__);

    if (mTunerService == nullptr) {
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_NO_INIT);
    if (mTuner == nullptr) {
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::NOT_INITIALIZED));
    }

    mFrontend = mTunerService->getFrontendById(in_frontendId);

    mFrontend = mTuner->getFrontendById(in_frontendId);
    if (mFrontend == nullptr) {
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_STATE));
    }

    mTunerService->setFrontendAsDemuxSource(in_frontendId, mDemuxId);
    mTuner->setFrontendAsDemuxSource(in_frontendId, mDemuxId);

    return ::ndk::ScopedAStatus::ok();
}
@@ -69,14 +71,16 @@ Demux::~Demux() {
    if (in_cb == nullptr) {
        ALOGW("[Demux] callback can't be null");
        *_aidl_return = nullptr;
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_ARGUMENT));
    }

    std::shared_ptr<Filter> filter =
            ndk::SharedRefBase::make<Filter>(in_type, filterId, in_bufferSize, in_cb, ref<Demux>());
    if (!filter->createFilterMQ()) {
        *_aidl_return = nullptr;
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_UNKNOWN_ERROR);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::UNKNOWN_ERROR));
    }

    mFilters[filterId] = filter;
@@ -95,7 +99,8 @@ Demux::~Demux() {

    if (!result) {
        *_aidl_return = nullptr;
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_ARGUMENT));
    }

    *_aidl_return = filter;
@@ -122,13 +127,15 @@ Demux::~Demux() {
    if (!status.isOk()) {
        ALOGE("[Demux] Can't get filter Id.");
        *_aidl_return = -1;
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_STATE));
    }

    if (!mFilters[id]->isMediaFilter()) {
        ALOGE("[Demux] Given filter is not a media filter.");
        *_aidl_return = -1;
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_STATE));
    }

    if (!mPcrFilterIds.empty()) {
@@ -139,7 +146,8 @@ Demux::~Demux() {

    ALOGE("[Demux] No PCR filter opened.");
    *_aidl_return = -1;
    return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
    return ::ndk::ScopedAStatus::fromServiceSpecificError(
            static_cast<int32_t>(Result::INVALID_STATE));
}

::ndk::ScopedAStatus Demux::getAvSyncTime(int32_t in_avSyncHwId, int64_t* _aidl_return) {
@@ -147,11 +155,13 @@ Demux::~Demux() {

    if (mPcrFilterIds.empty()) {
        *_aidl_return = -1;
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_STATE));
    }
    if (in_avSyncHwId != *mPcrFilterIds.begin()) {
        *_aidl_return = -1;
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_ARGUMENT));
    }

    *_aidl_return = -1;
@@ -169,7 +179,7 @@ Demux::~Demux() {
    mRecordFilterIds.clear();
    mFilters.clear();
    mLastUsedFilterId = -1;
    mTunerService->removeDemux(mDemuxId);
    mTuner->removeDemux(mDemuxId);
    mFrontendInputThreadRunning = false;
    std::lock_guard<std::mutex> lock(mFrontendInputThreadLock);

@@ -184,7 +194,8 @@ Demux::~Demux() {
    if (in_cb == nullptr) {
        ALOGW("[Demux] DVR callback can't be null");
        *_aidl_return = nullptr;
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_ARGUMENT));
    }

    set<int64_t>::iterator it;
@@ -195,7 +206,8 @@ Demux::~Demux() {
            if (!mDvrPlayback->createDvrMQ()) {
                mDvrPlayback = nullptr;
                *_aidl_return = mDvrPlayback;
                return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_UNKNOWN_ERROR);
                return ::ndk::ScopedAStatus::fromServiceSpecificError(
                        static_cast<int32_t>(Result::UNKNOWN_ERROR));
            }

            for (it = mPlaybackFilterIds.begin(); it != mPlaybackFilterIds.end(); it++) {
@@ -203,7 +215,8 @@ Demux::~Demux() {
                    ALOGE("[Demux] Can't get filter info for DVR playback");
                    mDvrPlayback = nullptr;
                    *_aidl_return = mDvrPlayback;
                    return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_UNKNOWN_ERROR);
                    return ::ndk::ScopedAStatus::fromServiceSpecificError(
                            static_cast<int32_t>(Result::UNKNOWN_ERROR));
                }
            }

@@ -214,14 +227,16 @@ Demux::~Demux() {
            if (!mDvrRecord->createDvrMQ()) {
                mDvrRecord = nullptr;
                *_aidl_return = mDvrRecord;
                return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_UNKNOWN_ERROR);
                return ::ndk::ScopedAStatus::fromServiceSpecificError(
                        static_cast<int32_t>(Result::UNKNOWN_ERROR));
            }

            *_aidl_return = mDvrRecord;
            return ::ndk::ScopedAStatus::ok();
        default:
            *_aidl_return = nullptr;
            return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
            return ::ndk::ScopedAStatus::fromServiceSpecificError(
                    static_cast<int32_t>(Result::INVALID_ARGUMENT));
    }
}

+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ class Demux : public BnDemux {

  private:
    // Tuner service
    std::shared_ptr<Tuner> mTunerService;
    std::shared_ptr<Tuner> mTuner;

    // Frontend source
    std::shared_ptr<Frontend> mFrontend;
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define LOG_TAG "android.hardware.tv.tuner-service.example-Descrambler"

#include <aidl/android/hardware/tv/tuner/IFrontendCallback.h>
#include <aidl/android/hardware/tv/tuner/Result.h>
#include <utils/Log.h>

#include "Descrambler.h"
@@ -37,7 +38,8 @@ Descrambler::~Descrambler() {}
    if (mDemuxSet) {
        ALOGW("[   WARN   ] Descrambler has already been set with a demux id %" PRIu32,
              mSourceDemuxId);
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_STATE));
    }
    mDemuxSet = true;
    mSourceDemuxId = in_demuxId;
+19 −20
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define LOG_TAG "android.hardware.tv.tuner-service.example-Dvr"

#include <aidl/android/hardware/tv/tuner/DemuxQueueNotifyBits.h>
#include <aidl/android/hardware/tv/tuner/Result.h>

#include <utils/Log.h>
#include "Dvr.h"
@@ -39,8 +40,8 @@ Dvr::Dvr(DvrType type, uint32_t bufferSize, const std::shared_ptr<IDvrCallback>&
}

Dvr::~Dvr() {
    mDvrThreadRunning = false;
    lock_guard<mutex> lock(mDvrThreadLock);
    // make sure thread has joined
    close();
}

::ndk::ScopedAStatus Dvr::getQueueDesc(MQDescriptor<int8_t, SynchronizedReadWrite>* out_queue) {
@@ -70,7 +71,8 @@ Dvr::~Dvr() {
    }

    if (!mDemux->attachRecordFilter(filterId)) {
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_ARGUMENT));
    }

    return ::ndk::ScopedAStatus::ok();
@@ -86,7 +88,8 @@ Dvr::~Dvr() {
    }

    if (!mDemux->detachRecordFilter(filterId)) {
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_ARGUMENT));
    }

    return ::ndk::ScopedAStatus::ok();
@@ -99,17 +102,18 @@ Dvr::~Dvr() {
    }

    if (!mCallback) {
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_NO_INIT);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::NOT_INITIALIZED));
    }

    if (!mDvrConfigured) {
        return ::ndk::ScopedAStatus::fromExceptionCode(STATUS_INVALID_OPERATION);
        return ::ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(Result::INVALID_STATE));
    }

    if (mType == DvrType::PLAYBACK) {
        mDvrThreadRunning = true;
        pthread_create(&mDvrThread, NULL, __threadLoopPlayback, this);
        pthread_setname_np(mDvrThread, "playback_waiting_loop");
        mDvrThread = std::thread(&Dvr::playbackThreadLoop, this);
    } else if (mType == DvrType::RECORD) {
        mRecordStatus = RecordStatus::DATA_READY;
        mDemux->setIsRecording(mType == DvrType::RECORD);
@@ -124,9 +128,11 @@ Dvr::~Dvr() {
    ALOGV("%s", __FUNCTION__);

    mDvrThreadRunning = false;
    lock_guard<mutex> lock(mDvrThreadLock);

    mIsRecordStarted = false;
    if (mDvrThread.joinable()) {
        mDvrThread.join();
    }
    // thread should always be joinable if it is running,
    // so it should be safe to assume recording stopped.
    mDemux->setIsRecording(false);

    return ::ndk::ScopedAStatus::ok();
@@ -143,8 +149,8 @@ Dvr::~Dvr() {
::ndk::ScopedAStatus Dvr::close() {
    ALOGV("%s", __FUNCTION__);

    mDvrThreadRunning = false;
    lock_guard<mutex> lock(mDvrThreadLock);
    stop();

    return ::ndk::ScopedAStatus::ok();
}

@@ -171,15 +177,8 @@ EventFlag* Dvr::getDvrEventFlag() {
    return mDvrEventFlag;
}

void* Dvr::__threadLoopPlayback(void* user) {
    Dvr* const self = static_cast<Dvr*>(user);
    self->playbackThreadLoop();
    return 0;
}

void Dvr::playbackThreadLoop() {
    ALOGD("[Dvr] playback threadLoop start.");
    lock_guard<mutex> lock(mDvrThreadLock);

    while (mDvrThreadRunning) {
        uint32_t efState = 0;
+4 −10
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@

#include <fmq/AidlMessageQueue.h>
#include <math.h>
#include <atomic>
#include <set>
#include <thread>
#include "Demux.h"
#include "Frontend.h"
#include "Tuner.h"
@@ -107,10 +109,7 @@ class Dvr : public BnDvr {
     * Each filter handler handles the data filtering/output writing/filterEvent updating.
     */
    void startTpidFilter(vector<int8_t> data);
    static void* __threadLoopPlayback(void* user);
    static void* __threadLoopRecord(void* user);
    void playbackThreadLoop();
    void recordThreadLoop();

    unique_ptr<DvrMQ> mDvrMQ;
    EventFlag* mDvrEventFlag;
@@ -121,7 +120,7 @@ class Dvr : public BnDvr {
    DvrSettings mDvrSettings;

    // Thread handlers
    pthread_t mDvrThread;
    std::thread mDvrThread;

    // FMQ status local records
    PlaybackStatus mPlaybackStatus;
@@ -129,7 +128,7 @@ class Dvr : public BnDvr {
    /**
     * If a specific filter's writing loop is still running
     */
    bool mDvrThreadRunning;
    std::atomic<bool> mDvrThreadRunning;
    bool mKeepFetchingDataFromFrontend;
    /**
     * Lock to protect writes to the FMQs
@@ -140,13 +139,8 @@ class Dvr : public BnDvr {
     */
    std::mutex mPlaybackStatusLock;
    std::mutex mRecordStatusLock;
    std::mutex mDvrThreadLock;

    const bool DEBUG_DVR = false;

    // Booleans to check if recording is running.
    // Recording is ready when both of the following are set to true.
    bool mIsRecordStarted = false;
};

}  // namespace tuner
Loading