Fix issues in Tuner VTS Dvr testing

This CL fixes the following issues:
1. Modified some unnecessary or not proper debug msg in the VTS/Default
impl
2. Some incorrect VTS testing order
3. Added a flush test on Dvr status
4. Used a ts from Android aosp cts for testing
5. Changed the configuration to run with the new ts on cf
6. Fixed some deadlock and logic issues in the VTS/Default
implementation

Test: atest VtsHalTvTunerV1_0TargetTest
Bug: 150989084
Bug: 153366959
Bug: 153367094
Change-Id: If7eb8534caff4fc11ac4e166ef5391e8f543408d
diff --git a/tv/tuner/1.0/vts/functional/DvrTests.cpp b/tv/tuner/1.0/vts/functional/DvrTests.cpp
index 9b24aa7..7e7f8e6 100644
--- a/tv/tuner/1.0/vts/functional/DvrTests.cpp
+++ b/tv/tuner/1.0/vts/functional/DvrTests.cpp
@@ -16,17 +16,13 @@
 
 #include "DvrTests.h"
 
-void DvrCallback::startPlaybackInputThread(PlaybackConf playbackConf,
+void DvrCallback::startPlaybackInputThread(string& dataInputFile, PlaybackSettings& settings,
                                            MQDesc& playbackMQDescriptor) {
+    mInputDataFile = dataInputFile;
+    mPlaybackSettings = settings;
     mPlaybackMQ = std::make_unique<FilterMQ>(playbackMQDescriptor, true /* resetPointers */);
     EXPECT_TRUE(mPlaybackMQ);
-    struct PlaybackThreadArgs* threadArgs =
-            (struct PlaybackThreadArgs*)malloc(sizeof(struct PlaybackThreadArgs));
-    threadArgs->user = this;
-    threadArgs->playbackConf = &playbackConf;
-    threadArgs->keepWritingPlaybackFMQ = &mKeepWritingPlaybackFMQ;
-
-    pthread_create(&mPlaybackThread, NULL, __threadLoopPlayback, (void*)threadArgs);
+    pthread_create(&mPlaybackThread, NULL, __threadLoopPlayback, this);
     pthread_setname_np(mPlaybackThread, "test_playback_input_loop");
 }
 
@@ -37,15 +33,13 @@
     android::Mutex::Autolock autoLock(mPlaybackThreadLock);
 }
 
-void* DvrCallback::__threadLoopPlayback(void* threadArgs) {
-    DvrCallback* const self =
-            static_cast<DvrCallback*>(((struct PlaybackThreadArgs*)threadArgs)->user);
-    self->playbackThreadLoop(((struct PlaybackThreadArgs*)threadArgs)->playbackConf,
-                             ((struct PlaybackThreadArgs*)threadArgs)->keepWritingPlaybackFMQ);
+void* DvrCallback::__threadLoopPlayback(void* user) {
+    DvrCallback* const self = static_cast<DvrCallback*>(user);
+    self->playbackThreadLoop();
     return 0;
 }
 
-void DvrCallback::playbackThreadLoop(PlaybackConf* playbackConf, bool* keepWritingPlaybackFMQ) {
+void DvrCallback::playbackThreadLoop() {
     android::Mutex::Autolock autoLock(mPlaybackThreadLock);
     mPlaybackThreadRunning = true;
 
@@ -56,10 +50,10 @@
                 android::OK);
 
     // open the stream and get its length
-    std::ifstream inputData(playbackConf->inputDataFile, std::ifstream::binary);
-    int writeSize = playbackConf->setting.packetSize * 6;
+    std::ifstream inputData(mInputDataFile.c_str(), std::ifstream::binary);
+    int writeSize = mPlaybackSettings.packetSize * 6;
     char* buffer = new char[writeSize];
-    ALOGW("[vts] playback thread loop start %s", playbackConf->inputDataFile.c_str());
+    ALOGW("[vts] playback thread loop start %s!", mInputDataFile.c_str());
     if (!inputData.is_open()) {
         mPlaybackThreadRunning = false;
         ALOGW("[vts] Error %s", strerror(errno));
@@ -67,7 +61,7 @@
 
     while (mPlaybackThreadRunning) {
         // move the stream pointer for packet size * 6 every read until the end
-        while (*keepWritingPlaybackFMQ) {
+        while (mKeepWritingPlaybackFMQ) {
             inputData.read(buffer, writeSize);
             if (!inputData) {
                 int leftSize = inputData.gcount();
@@ -105,6 +99,7 @@
     while (mDataOutputBuffer.empty()) {
         if (-ETIMEDOUT == mMsgCondition.waitRelative(mMsgLock, WAIT_TIMEOUT)) {
             EXPECT_TRUE(false) << "record output matching pid does not output within timeout";
+            stopRecordThread();
             return;
         }
     }
@@ -138,6 +133,7 @@
     ALOGD("[vts] DvrCallback record threadLoop start.");
     android::Mutex::Autolock autoLock(mRecordThreadLock);
     mRecordThreadRunning = true;
+    mKeepReadingRecordFMQ = true;
 
     // Create the EventFlag that is used to signal the HAL impl that data have been
     // read from the Record FMQ
@@ -183,7 +179,6 @@
 void DvrCallback::stopRecordThread() {
     mKeepReadingRecordFMQ = false;
     mRecordThreadRunning = false;
-    android::Mutex::Autolock autoLock(mRecordThreadLock);
 }
 
 AssertionResult DvrTests::openDvrInDemux(DvrType type, uint32_t bufferSize) {
@@ -198,6 +193,9 @@
         status = result;
     });
 
+    if (status == Result::SUCCESS) {
+        mDvrCallback->setDvr(mDvr);
+    }
     return AssertionResult(status == Result::SUCCESS);
 }