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

Commit 69176b80 authored by Android Build Prod User's avatar Android Build Prod User Committed by Android (Google) Code Review
Browse files

Merge "Refine tuner aidl hal threads."

parents d70bab92 901aa7b7
Loading
Loading
Loading
Loading
+7 −14
Original line number Diff line number Diff line
@@ -37,8 +37,7 @@ Demux::Demux(int32_t demuxId, std::shared_ptr<Tuner> tuner) {
}

Demux::~Demux() {
    mFrontendInputThreadRunning = false;
    std::lock_guard<std::mutex> lock(mFrontendInputThreadLock);
    close();
}

::ndk::ScopedAStatus Demux::setFrontendDataSource(int32_t in_frontendId) {
@@ -171,6 +170,8 @@ Demux::~Demux() {
::ndk::ScopedAStatus Demux::close() {
    ALOGV("%s", __FUNCTION__);

    stopFrontendInput();

    set<int64_t>::iterator it;
    for (it = mPlaybackFilterIds.begin(); it != mPlaybackFilterIds.end(); it++) {
        mDvrPlayback->removePlaybackFilter(*it);
@@ -180,8 +181,6 @@ Demux::~Demux() {
    mFilters.clear();
    mLastUsedFilterId = -1;
    mTuner->removeDemux(mDemuxId);
    mFrontendInputThreadRunning = false;
    std::lock_guard<std::mutex> lock(mFrontendInputThreadLock);

    return ::ndk::ScopedAStatus::ok();
}
@@ -345,14 +344,7 @@ uint16_t Demux::getFilterTpid(int64_t filterId) {

void Demux::startFrontendInputLoop() {
    mFrontendInputThreadRunning = true;
    pthread_create(&mFrontendInputThread, NULL, __threadLoopFrontend, this);
    pthread_setname_np(mFrontendInputThread, "frontend_input_thread");
}

void* Demux::__threadLoopFrontend(void* user) {
    Demux* const self = static_cast<Demux*>(user);
    self->frontendInputThreadLoop();
    return 0;
    mFrontendInputThread = std::thread(&Demux::frontendInputThreadLoop, this);
}

void Demux::frontendInputThreadLoop() {
@@ -360,7 +352,6 @@ void Demux::frontendInputThreadLoop() {
        return;
    }

    std::lock_guard<std::mutex> lock(mFrontendInputThreadLock);
    if (!mDvrPlayback) {
        ALOGW("[Demux] No software Frontend input configured. Ending Frontend thread loop.");
        mFrontendInputThreadRunning = false;
@@ -402,7 +393,9 @@ void Demux::stopFrontendInput() {
    ALOGD("[Demux] stop frontend on demux");
    mKeepFetchingDataFromFrontend = false;
    mFrontendInputThreadRunning = false;
    std::lock_guard<std::mutex> lock(mFrontendInputThreadLock);
    if (mFrontendInputThread.joinable()) {
        mFrontendInputThread.join();
    }
}

void Demux::setIsRecording(bool isRecording) {
+8 −7
Original line number Diff line number Diff line
@@ -20,7 +20,10 @@

#include <fmq/AidlMessageQueue.h>
#include <math.h>
#include <atomic>
#include <set>
#include <thread>

#include "Dvr.h"
#include "Filter.h"
#include "Frontend.h"
@@ -155,12 +158,14 @@ class Demux : public BnDemux {
    std::shared_ptr<Dvr> mDvrRecord;

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

    /**
     * If a specific filter's writing loop is still running
     */
    bool mFrontendInputThreadRunning;
    bool mKeepFetchingDataFromFrontend;
    std::atomic<bool> mFrontendInputThreadRunning;
    std::atomic<bool> mKeepFetchingDataFromFrontend;

    /**
     * If the dvr recording is running.
     */
@@ -169,10 +174,6 @@ class Demux : public BnDemux {
     * Lock to protect writes to the FMQs
     */
    std::mutex mWriteLock;
    /**
     * Lock to protect writes to the input status
     */
    std::mutex mFrontendInputThreadLock;

    // temp handle single PES filter
    // TODO handle mulptiple Pes filters
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ class Dvr : public BnDvr {
     * If a specific filter's writing loop is still running
     */
    std::atomic<bool> mDvrThreadRunning;
    bool mKeepFetchingDataFromFrontend;

    /**
     * Lock to protect writes to the FMQs
     */
+10 −14
Original line number Diff line number Diff line
@@ -85,8 +85,7 @@ Filter::Filter(DemuxFilterType type, int64_t filterId, uint32_t bufferSize,
}

Filter::~Filter() {
    mFilterThreadRunning = false;
    std::lock_guard<std::mutex> lock(mFilterThreadLock);
    close();
}

::ndk::ScopedAStatus Filter::getId64Bit(int64_t* _aidl_return) {
@@ -187,8 +186,12 @@ Filter::~Filter() {

::ndk::ScopedAStatus Filter::stop() {
    ALOGV("%s", __FUNCTION__);

    mFilterThreadRunning = false;
    std::lock_guard<std::mutex> lock(mFilterThreadLock);
    if (mFilterThread.joinable()) {
        mFilterThread.join();
    }

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

@@ -226,8 +229,8 @@ Filter::~Filter() {
::ndk::ScopedAStatus Filter::close() {
    ALOGV("%s", __FUNCTION__);

    mFilterThreadRunning = false;
    std::lock_guard<std::mutex> lock(mFilterThreadLock);
    stop();

    return mDemux->removeFilter(mFilterId);
}

@@ -376,22 +379,15 @@ bool Filter::createFilterMQ() {
}

::ndk::ScopedAStatus Filter::startFilterLoop() {
    pthread_create(&mFilterThread, NULL, __threadLoopFilter, this);
    pthread_setname_np(mFilterThread, "filter_waiting_loop");
    mFilterThread = std::thread(&Filter::filterThreadLoop, this);
    return ::ndk::ScopedAStatus::ok();
}

void* Filter::__threadLoopFilter(void* user) {
    Filter* const self = static_cast<Filter*>(user);
    self->filterThreadLoop();
    return 0;
}

void Filter::filterThreadLoop() {
    if (!mFilterThreadRunning) {
        return;
    }
    std::lock_guard<std::mutex> lock(mFilterThreadLock);

    ALOGD("[Filter] filter %" PRIu64 " threadLoop start.", mFilterId);

    // For the first time of filter output, implementation needs to send the filter
+5 −4
Original line number Diff line number Diff line
@@ -24,7 +24,10 @@
#include <ion/ion.h>
#include <math.h>
#include <sys/stat.h>
#include <atomic>
#include <set>
#include <thread>

#include "Demux.h"
#include "Dvr.h"
#include "Frontend.h"
@@ -126,15 +129,14 @@ class Filter : public BnFilter {
    vector<DemuxFilterEvent> mFilterEvents;

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

    // FMQ status local records
    DemuxFilterStatus mFilterStatus;
    /**
     * If a specific filter's writing loop is still running
     */
    bool mFilterThreadRunning;
    bool mKeepFetchingDataFromFrontend;
    std::atomic<bool> mFilterThreadRunning;

    /**
     * How many times a filter should write
@@ -204,7 +206,6 @@ class Filter : public BnFilter {
     * Lock to protect writes to the input status
     */
    std::mutex mFilterStatusLock;
    std::mutex mFilterThreadLock;
    std::mutex mFilterOutputLock;
    std::mutex mRecordFilterOutputLock;

Loading