blob: 492f2f00c5bb7dee909b51e30c64b0df42876dbe [file] [log] [blame]
Amy Zhang45cc57a2020-07-09 22:56:25 -07001/*
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/types.h>
21#include <android/hardware/tv/tuner/1.1/ITuner.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
Amy Zhang68afca62020-07-20 18:28:58 -070034#include "DvrTests.h"
Amy Zhang45cc57a2020-07-09 22:56:25 -070035#include "VtsHalTvTunerV1_1TestConfigurations.h"
36
37#define WAIT_TIMEOUT 3000000000
38#define INVALID_ID -1
39
40using android::Condition;
41using android::IMemory;
42using android::IMemoryHeap;
43using android::MemoryDealer;
44using android::Mutex;
45using android::sp;
46using android::hardware::fromHeap;
47using android::hardware::hidl_vec;
48using android::hardware::Return;
49using android::hardware::Void;
50using android::hardware::tv::tuner::V1_0::FrontendEventType;
51using android::hardware::tv::tuner::V1_0::FrontendId;
52using android::hardware::tv::tuner::V1_0::FrontendInfo;
53using android::hardware::tv::tuner::V1_0::FrontendScanMessage;
54using android::hardware::tv::tuner::V1_0::FrontendScanMessageType;
55using android::hardware::tv::tuner::V1_0::IFrontend;
56using android::hardware::tv::tuner::V1_0::IFrontendCallback;
57using android::hardware::tv::tuner::V1_0::Result;
58using android::hardware::tv::tuner::V1_1::ITuner;
59
60using ::testing::AssertionResult;
61
62using namespace std;
63
64#define INVALID_ID -1
Amy Zhang68afca62020-07-20 18:28:58 -070065#define WAIT_TIMEOUT 3000000000
Amy Zhang45cc57a2020-07-09 22:56:25 -070066
67class FrontendCallback : public IFrontendCallback {
68 public:
69 virtual Return<void> onEvent(FrontendEventType frontendEventType) override;
70 virtual Return<void> onScanMessage(FrontendScanMessageType type,
71 const FrontendScanMessage& message) override;
Amy Zhang68afca62020-07-20 18:28:58 -070072
73 void tuneTestOnLock(sp<IFrontend>& frontend, FrontendSettings settings);
74
75 private:
76 bool mEventReceived = false;
77 bool mLockMsgReceived = false;
78 hidl_vec<uint8_t> mEventMessage;
79 android::Mutex mMsgLock;
80 android::Condition mMsgCondition;
81 android::Condition mLockMsgCondition;
Amy Zhang45cc57a2020-07-09 22:56:25 -070082};
83
84class FrontendTests {
85 public:
86 sp<ITuner> mService;
87
Amy Zhang68afca62020-07-20 18:28:58 -070088 void setService(sp<ITuner> tuner) {
89 mService = tuner;
90 mDvrTests.setService(tuner);
91 getDefaultSoftwareFrontendPlaybackConfig(mDvrConfig);
92 }
Amy Zhang45cc57a2020-07-09 22:56:25 -070093
94 AssertionResult getFrontendIds();
95 AssertionResult getFrontendInfo(uint32_t frontendId);
96 AssertionResult openFrontendById(uint32_t frontendId);
97 AssertionResult setFrontendCallback();
Amy Zhang68afca62020-07-20 18:28:58 -070098 AssertionResult tuneFrontend(FrontendConfig config, bool testWithDemux);
99 AssertionResult stopTuneFrontend(bool testWithDemux);
Amy Zhang45cc57a2020-07-09 22:56:25 -0700100 AssertionResult closeFrontend();
101
102 void getFrontendIdByType(FrontendType feType, uint32_t& feId);
103
Amy Zhang68afca62020-07-20 18:28:58 -0700104 void setDvrTests(DvrTests dvrTests) { mDvrTests = dvrTests; }
105 void setDemux(sp<IDemux> demux) { mDvrTests.setDemux(demux); }
106 void setSoftwareFrontendDvrConfig(DvrConfig conf) { mDvrConfig = conf; }
107
Amy Zhang45cc57a2020-07-09 22:56:25 -0700108 protected:
109 static AssertionResult failure() { return ::testing::AssertionFailure(); }
110 static AssertionResult success() { return ::testing::AssertionSuccess(); }
111
Amy Zhang68afca62020-07-20 18:28:58 -0700112 void getDefaultSoftwareFrontendPlaybackConfig(DvrConfig& dvrConfig) {
113 PlaybackSettings playbackSettings{
114 .statusMask = 0xf,
115 .lowThreshold = 0x1000,
116 .highThreshold = 0x07fff,
117 .dataFormat = DataFormat::ES,
118 .packetSize = 188,
119 };
120 dvrConfig.type = DvrType::PLAYBACK;
121 dvrConfig.playbackInputFile = "/data/local/tmp/test.es";
122 dvrConfig.bufferSize = FMQ_SIZE_4M;
123 dvrConfig.settings.playback(playbackSettings);
124 }
125
Amy Zhang45cc57a2020-07-09 22:56:25 -0700126 sp<IFrontend> mFrontend;
127 FrontendInfo mFrontendInfo;
128 sp<FrontendCallback> mFrontendCallback;
129 hidl_vec<FrontendId> mFeIds;
130
Amy Zhang68afca62020-07-20 18:28:58 -0700131 DvrTests mDvrTests;
Amy Zhang45cc57a2020-07-09 22:56:25 -0700132 bool mIsSoftwareFe = false;
Amy Zhang68afca62020-07-20 18:28:58 -0700133 DvrConfig mDvrConfig;
134};