Add reference counter for Filter

Filters should start demux reading thread for IPTV when start()
is called and they should PAUSE the thread when stop() is called.
They should only be paused when all associated filters of the
demux are closed. This CL adds reference counters for filters to
track that.

Bug: 288170590
Test: manual
Change-Id: I087175a685a4559918ceaa511971b79e7fcb0a51
diff --git a/tv/tuner/aidl/default/Filter.cpp b/tv/tuner/aidl/default/Filter.cpp
index 7b62c3e..d8f5dd5 100644
--- a/tv/tuner/aidl/default/Filter.cpp
+++ b/tv/tuner/aidl/default/Filter.cpp
@@ -326,6 +326,8 @@
     ALOGV("%s", __FUNCTION__);
     mFilterThreadRunning = true;
     std::vector<DemuxFilterEvent> events;
+
+    mFilterCount += 1;
     // All the filter event callbacks in start are for testing purpose.
     switch (mType.mainType) {
         case DemuxFilterMainType::TS:
@@ -362,6 +364,8 @@
 ::ndk::ScopedAStatus Filter::stop() {
     ALOGV("%s", __FUNCTION__);
 
+    mFilterCount -= 1;
+
     mFilterThreadRunning = false;
     if (mFilterThread.joinable()) {
         mFilterThread.join();
diff --git a/tv/tuner/aidl/default/Filter.h b/tv/tuner/aidl/default/Filter.h
index 1cf6b3a..e2a0c7a 100644
--- a/tv/tuner/aidl/default/Filter.h
+++ b/tv/tuner/aidl/default/Filter.h
@@ -289,6 +289,7 @@
     uint8_t mIpCidMonitored = 0;
 
     PlaybackStatus mIptvDvrPlaybackStatus;
+    std::atomic<int> mFilterCount = 0;
 };
 
 }  // namespace tuner