1 /* 2 * Copyright 2020 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 #include <android-base/logging.h> 18 #include <android/hardware/tv/tuner/1.0/IFrontend.h> 19 #include <android/hardware/tv/tuner/1.0/IFrontendCallback.h> 20 #include <android/hardware/tv/tuner/1.0/ITuner.h> 21 #include <android/hardware/tv/tuner/1.0/types.h> 22 #include <binder/MemoryDealer.h> 23 #include <gtest/gtest.h> 24 #include <hidl/GtestPrinter.h> 25 #include <hidl/HidlSupport.h> 26 #include <hidl/HidlTransportSupport.h> 27 #include <hidl/ServiceManagement.h> 28 #include <hidl/Status.h> 29 #include <hidlmemory/FrameworkUtils.h> 30 #include <utils/Condition.h> 31 #include <utils/Mutex.h> 32 #include <map> 33 34 #include "DvrTests.h" 35 #include "VtsHalTvTunerV1_0TestConfigurations.h" 36 37 #define WAIT_TIMEOUT 3000000000 38 #define INVALID_ID -1 39 40 using android::Condition; 41 using android::IMemory; 42 using android::IMemoryHeap; 43 using android::MemoryDealer; 44 using android::Mutex; 45 using android::sp; 46 using android::hardware::fromHeap; 47 using android::hardware::hidl_vec; 48 using android::hardware::Return; 49 using android::hardware::Void; 50 using android::hardware::tv::tuner::V1_0::FrontendAtscModulation; 51 using android::hardware::tv::tuner::V1_0::FrontendAtscSettings; 52 using android::hardware::tv::tuner::V1_0::FrontendDvbtSettings; 53 using android::hardware::tv::tuner::V1_0::FrontendEventType; 54 using android::hardware::tv::tuner::V1_0::FrontendId; 55 using android::hardware::tv::tuner::V1_0::FrontendInfo; 56 using android::hardware::tv::tuner::V1_0::FrontendInnerFec; 57 using android::hardware::tv::tuner::V1_0::FrontendScanMessage; 58 using android::hardware::tv::tuner::V1_0::FrontendScanMessageType; 59 using android::hardware::tv::tuner::V1_0::FrontendScanType; 60 using android::hardware::tv::tuner::V1_0::FrontendSettings; 61 using android::hardware::tv::tuner::V1_0::IFrontend; 62 using android::hardware::tv::tuner::V1_0::IFrontendCallback; 63 using android::hardware::tv::tuner::V1_0::ITuner; 64 using android::hardware::tv::tuner::V1_0::Result; 65 66 using ::testing::AssertionResult; 67 68 using namespace std; 69 70 #define INVALID_ID -1 71 #define WAIT_TIMEOUT 3000000000 72 73 class FrontendCallback : public IFrontendCallback { 74 public: 75 virtual Return<void> onEvent(FrontendEventType frontendEventType) override; 76 virtual Return<void> onScanMessage(FrontendScanMessageType type, 77 const FrontendScanMessage& message) override; 78 79 void tuneTestOnEventReceive(sp<IFrontend>& frontend, FrontendSettings settings); 80 void tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings); 81 void scanTest(sp<IFrontend>& frontend, FrontendConfig config, FrontendScanType type); 82 83 // Helper methods 84 uint32_t getTargetFrequency(FrontendSettings settings, FrontendType type); 85 void resetBlindScanStartingFrequency(FrontendConfig& config, uint32_t resetingFreq); 86 87 private: 88 bool mEventReceived = false; 89 bool mScanMessageReceived = false; 90 bool mLockMsgReceived = false; 91 bool mScanMsgProcessed = true; 92 FrontendScanMessageType mScanMessageType; 93 FrontendScanMessage mScanMessage; 94 hidl_vec<uint8_t> mEventMessage; 95 android::Mutex mMsgLock; 96 android::Condition mMsgCondition; 97 android::Condition mLockMsgCondition; 98 }; 99 100 class FrontendTests { 101 public: 102 sp<ITuner> mService; 103 setService(sp<ITuner> tuner)104 void setService(sp<ITuner> tuner) { 105 mService = tuner; 106 mDvrTests.setService(tuner); 107 } 108 109 AssertionResult getFrontendIds(); 110 AssertionResult getFrontendInfo(uint32_t frontendId); 111 AssertionResult openFrontendById(uint32_t frontendId); 112 AssertionResult setFrontendCallback(); 113 AssertionResult scanFrontend(FrontendConfig config, FrontendScanType type); 114 AssertionResult stopScanFrontend(); 115 AssertionResult tuneFrontend(FrontendConfig config, bool testWithDemux); 116 AssertionResult setLnb(uint32_t lnbId); 117 void verifyFrontendStatus(vector<FrontendStatusType> statusTypes, 118 vector<FrontendStatus> expectStatuses); 119 AssertionResult stopTuneFrontend(bool testWithDemux); 120 AssertionResult closeFrontend(); 121 122 void getFrontendIdByType(FrontendType feType, uint32_t& feId); 123 void tuneTest(FrontendConfig frontendConf); 124 void scanTest(FrontendConfig frontend, FrontendScanType type); 125 setDvrTests(DvrTests dvrTests)126 void setDvrTests(DvrTests dvrTests) { mDvrTests = dvrTests; } setDemux(sp<IDemux> demux)127 void setDemux(sp<IDemux> demux) { mDvrTests.setDemux(demux); } 128 129 protected: failure()130 static AssertionResult failure() { return ::testing::AssertionFailure(); } success()131 static AssertionResult success() { return ::testing::AssertionSuccess(); } 132 getSoftwareFrontendPlaybackConfig(DvrConfig & dvrConfig)133 void getSoftwareFrontendPlaybackConfig(DvrConfig& dvrConfig) { 134 PlaybackSettings playbackSettings{ 135 .statusMask = 0xf, 136 .lowThreshold = 0x1000, 137 .highThreshold = 0x07fff, 138 .dataFormat = DataFormat::TS, 139 .packetSize = 188, 140 }; 141 dvrConfig.type = DvrType::PLAYBACK; 142 dvrConfig.playbackInputFile = "/data/local/tmp/segment000000.ts"; 143 dvrConfig.bufferSize = FMQ_SIZE_4M; 144 dvrConfig.settings.playback(playbackSettings); 145 } 146 147 sp<IFrontend> mFrontend; 148 FrontendInfo mFrontendInfo; 149 sp<FrontendCallback> mFrontendCallback; 150 hidl_vec<FrontendId> mFeIds; 151 152 DvrTests mDvrTests; 153 bool mIsSoftwareFe = false; 154 }; 155