1 /* 2 * Copyright 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <aidl/android/hardware/tv/tuner/BnFrontendCallback.h> 20 #include <aidl/android/hardware/tv/tuner/IFrontend.h> 21 #include <aidl/android/hardware/tv/tuner/ITuner.h> 22 23 #include <gtest/gtest.h> 24 #include <log/log.h> 25 #include <utils/Condition.h> 26 #include <utils/Mutex.h> 27 28 #include "DvrTests.h" 29 #include "VtsHalTvTunerTestConfigurations.h" 30 #include "utils/IpStreamer.h" 31 32 #define WAIT_TIMEOUT 3000000000 33 #define INVALID_ID -1 34 35 using android::Condition; 36 using android::Mutex; 37 38 using ::testing::AssertionResult; 39 40 using namespace aidl::android::hardware::tv::tuner; 41 using namespace std; 42 43 #define INVALID_ID -1 44 #define WAIT_TIMEOUT 3000000000 45 46 class FrontendCallback : public BnFrontendCallback { 47 public: 48 virtual ndk::ScopedAStatus onEvent(FrontendEventType frontendEventType) override; 49 virtual ndk::ScopedAStatus onScanMessage(FrontendScanMessageType type, 50 const FrontendScanMessage& message) override; 51 52 void tuneTestOnLock(std::shared_ptr<IFrontend>& frontend, FrontendSettings settings); 53 void scanTest(std::shared_ptr<IFrontend>& frontend, FrontendConfig config, 54 FrontendScanType type); 55 56 // Helper methods 57 int64_t getTargetFrequency(FrontendSettings& settings); 58 void resetBlindScanStartingFrequency(FrontendConfig& config, int64_t resetingFreq); 59 60 private: 61 void readFrontendScanMessage_Modulation(FrontendModulation modulation); 62 63 bool mEventReceived = false; 64 bool mScanMessageReceived = false; 65 bool mLockMsgReceived = false; 66 bool mScanMsgProcessed = true; 67 FrontendScanMessageType mScanMessageType; 68 FrontendScanMessage mScanMessage; 69 vector<int8_t> mEventMessage; 70 android::Mutex mMsgLock; 71 android::Condition mMsgCondition; 72 android::Condition mLockMsgCondition; 73 }; 74 75 class FrontendTests { 76 public: setService(std::shared_ptr<ITuner> tuner)77 void setService(std::shared_ptr<ITuner> tuner) { 78 mService = tuner; 79 getDvrTests()->setService(tuner); 80 getDefaultSoftwareFrontendPlaybackConfig(mDvrConfig); 81 } 82 83 AssertionResult getFrontendIds(); 84 AssertionResult getFrontendInfo(int32_t frontendId); 85 AssertionResult openFrontendById(int32_t frontendId); 86 AssertionResult setFrontendCallback(); 87 AssertionResult scanFrontend(FrontendConfig config, FrontendScanType type); 88 AssertionResult stopScanFrontend(); 89 AssertionResult setLnb(int32_t lnbId); 90 AssertionResult tuneFrontend(FrontendConfig config, bool testWithDemux); 91 void verifyFrontendStatus(vector<FrontendStatusType> statusTypes, 92 vector<FrontendStatus> expectStatuses); 93 AssertionResult stopTuneFrontend(bool testWithDemux); 94 AssertionResult closeFrontend(); 95 96 AssertionResult linkCiCam(int32_t ciCamId); 97 AssertionResult unlinkCiCam(int32_t ciCamId); 98 AssertionResult verifyHardwareInfo(); 99 AssertionResult removeOutputPid(int32_t removePid); 100 101 void getFrontendIdByType(FrontendType feType, int32_t& feId); 102 void tuneTest(FrontendConfig frontendConf); 103 void scanTest(FrontendConfig frontend, FrontendScanType type); 104 void debugInfoTest(FrontendConfig frontendConf); 105 void maxNumberOfFrontendsTest(); 106 void statusReadinessTest(FrontendConfig frontendConf); 107 setDvrTests(DvrTests * dvrTests)108 void setDvrTests(DvrTests* dvrTests) { mExternalDvrTests = dvrTests; } setDemux(std::shared_ptr<IDemux> demux)109 void setDemux(std::shared_ptr<IDemux> demux) { getDvrTests()->setDemux(demux); } setSoftwareFrontendDvrConfig(DvrConfig conf)110 void setSoftwareFrontendDvrConfig(DvrConfig conf) { mDvrConfig = conf; } 111 112 protected: failure()113 static AssertionResult failure() { return ::testing::AssertionFailure(); } success()114 static AssertionResult success() { return ::testing::AssertionSuccess(); } 115 getDefaultSoftwareFrontendPlaybackConfig(DvrConfig & dvrConfig)116 void getDefaultSoftwareFrontendPlaybackConfig(DvrConfig& dvrConfig) { 117 PlaybackSettings playbackSettings{ 118 .statusMask = 0xf, 119 .lowThreshold = 0x1000, 120 .highThreshold = 0x07fff, 121 .dataFormat = DataFormat::ES, 122 .packetSize = static_cast<int64_t>(188), 123 }; 124 dvrConfig.type = DvrType::PLAYBACK; 125 dvrConfig.playbackInputFile = "/data/local/tmp/test.es"; 126 dvrConfig.bufferSize = FMQ_SIZE_4M; 127 dvrConfig.settings.set<DvrSettings::playback>(playbackSettings); 128 } 129 getDvrTests()130 DvrTests* getDvrTests() { 131 return (mExternalDvrTests != nullptr ? mExternalDvrTests : &mDvrTests); 132 } 133 134 std::shared_ptr<ITuner> mService; 135 std::shared_ptr<IFrontend> mFrontend; 136 FrontendInfo mFrontendInfo; 137 std::shared_ptr<FrontendCallback> mFrontendCallback; 138 vector<int32_t> mFeIds; 139 140 DvrTests mDvrTests; 141 DvrTests* mExternalDvrTests = nullptr; 142 bool mIsSoftwareFe = false; 143 DvrConfig mDvrConfig; 144 }; 145