• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/hardware/tv/tuner/1.0/types.h>
18 #include <binder/MemoryDealer.h>
19 #include <hidl/HidlSupport.h>
20 #include <hidl/HidlTransportSupport.h>
21 #include <hidl/Status.h>
22 #include <hidlmemory/FrameworkUtils.h>
23 
24 #include "../../../config/TunerTestingConfigReaderV1_1.h"
25 
26 using android::hardware::tv::tuner::V1_0::DataFormat;
27 using android::hardware::tv::tuner::V1_0::DemuxAlpFilterType;
28 using android::hardware::tv::tuner::V1_0::DemuxFilterMainType;
29 using android::hardware::tv::tuner::V1_0::DemuxFilterSettings;
30 using android::hardware::tv::tuner::V1_0::DemuxFilterType;
31 using android::hardware::tv::tuner::V1_0::DemuxIpAddress;
32 using android::hardware::tv::tuner::V1_0::DemuxIpFilterSettings;
33 using android::hardware::tv::tuner::V1_0::DemuxIpFilterType;
34 using android::hardware::tv::tuner::V1_0::DemuxMmtpFilterType;
35 using android::hardware::tv::tuner::V1_0::DemuxRecordScIndexType;
36 using android::hardware::tv::tuner::V1_0::DemuxTsFilterType;
37 using android::hardware::tv::tuner::V1_0::DvrSettings;
38 using android::hardware::tv::tuner::V1_0::DvrType;
39 using android::hardware::tv::tuner::V1_0::FrontendDvbtBandwidth;
40 using android::hardware::tv::tuner::V1_0::FrontendDvbtCoderate;
41 using android::hardware::tv::tuner::V1_0::FrontendDvbtConstellation;
42 using android::hardware::tv::tuner::V1_0::FrontendDvbtGuardInterval;
43 using android::hardware::tv::tuner::V1_0::FrontendDvbtHierarchy;
44 using android::hardware::tv::tuner::V1_0::FrontendDvbtSettings;
45 using android::hardware::tv::tuner::V1_0::FrontendDvbtStandard;
46 using android::hardware::tv::tuner::V1_0::FrontendDvbtTransmissionMode;
47 using android::hardware::tv::tuner::V1_0::FrontendSettings;
48 using android::hardware::tv::tuner::V1_0::FrontendType;
49 using android::hardware::tv::tuner::V1_0::PlaybackSettings;
50 using android::hardware::tv::tuner::V1_0::RecordSettings;
51 
52 using namespace std;
53 using namespace android::media::tuner::testing::configuration::V1_0;
54 
55 const uint32_t FMQ_SIZE_4M = 0x400000;
56 const uint32_t FMQ_SIZE_16M = 0x1000000;
57 
58 const string configFilePath = "/vendor/etc/tuner_vts_config_1_1.xml";
59 
60 // Hardware configs
61 static map<string, FrontendConfig1_1> frontendMap;
62 static map<string, FilterConfig1_1> filterMap;
63 static map<string, DvrConfig> dvrMap;
64 
65 // Hardware and test cases connections
66 static LiveBroadcastHardwareConnections live;
67 static ScanHardwareConnections scan;
68 static DvrRecordHardwareConnections record;
69 
70 /** Config all the frontends that would be used in the tests */
initFrontendConfig()71 inline void initFrontendConfig() {
72     // The test will use the internal default fe when default fe is connected to any data flow
73     // without overriding in the xml config.
74     string defaultFeId = "FE_DEFAULT";
75     FrontendDvbtSettings dvbtSettings{
76             .frequency = 578000000,
77             .transmissionMode = FrontendDvbtTransmissionMode::AUTO,
78             .bandwidth = FrontendDvbtBandwidth::BANDWIDTH_8MHZ,
79             .isHighPriority = true,
80     };
81     frontendMap[defaultFeId].config1_0.type = FrontendType::DVBT;
82     frontendMap[defaultFeId].config1_0.settings.dvbt(dvbtSettings);
83 
84     vector<FrontendStatusTypeExt1_1> types;
85     types.push_back(FrontendStatusTypeExt1_1::UEC);
86     types.push_back(FrontendStatusTypeExt1_1::IS_MISO);
87     vector<FrontendStatusExt1_1> statuses;
88     FrontendStatusExt1_1 status;
89     status.uec(0);
90     statuses.push_back(status);
91     status.isMiso(true);
92     statuses.push_back(status);
93     frontendMap[defaultFeId].tuneStatusTypes = types;
94     frontendMap[defaultFeId].expectTuneStatuses = statuses;
95     frontendMap[defaultFeId].config1_0.isSoftwareFe = true;
96     frontendMap[defaultFeId].canConnectToCiCam = true;
97     frontendMap[defaultFeId].ciCamId = 0;
98     frontendMap[defaultFeId].settingsExt1_1.settingExt.dvbt({
99             .transmissionMode =
100                     android::hardware::tv::tuner::V1_1::FrontendDvbtTransmissionMode::MODE_8K_E,
101     });
102     // Read customized config
103     TunerTestingConfigReader1_1::readFrontendConfig1_1(frontendMap);
104 };
105 
initFilterConfig()106 inline void initFilterConfig() {
107     // The test will use the internal default filter when default filter is connected to any
108     // data flow without overriding in the xml config.
109     string defaultAudioFilterId = "FILTER_AUDIO_DEFAULT";
110     string defaultVideoFilterId = "FILTER_VIDEO_DEFAULT";
111 
112     filterMap[defaultVideoFilterId].config1_0.type.mainType = DemuxFilterMainType::TS;
113     filterMap[defaultVideoFilterId].config1_0.type.subType.tsFilterType(DemuxTsFilterType::VIDEO);
114     filterMap[defaultVideoFilterId].config1_0.bufferSize = FMQ_SIZE_16M;
115     filterMap[defaultVideoFilterId].config1_0.settings.ts().tpid = 256;
116     filterMap[defaultVideoFilterId].config1_0.settings.ts().filterSettings.av(
117             {.isPassthrough = false});
118     filterMap[defaultVideoFilterId].monitorEventTypes =
119             android::hardware::tv::tuner::V1_1::DemuxFilterMonitorEventType::SCRAMBLING_STATUS |
120             android::hardware::tv::tuner::V1_1::DemuxFilterMonitorEventType::IP_CID_CHANGE;
121     filterMap[defaultVideoFilterId].streamType.video(VideoStreamType::MPEG1);
122 
123     filterMap[defaultAudioFilterId].config1_0.type.mainType = DemuxFilterMainType::TS;
124     filterMap[defaultAudioFilterId].config1_0.type.subType.tsFilterType(DemuxTsFilterType::AUDIO);
125     filterMap[defaultAudioFilterId].config1_0.bufferSize = FMQ_SIZE_16M;
126     filterMap[defaultAudioFilterId].config1_0.settings.ts().tpid = 256;
127     filterMap[defaultAudioFilterId].config1_0.settings.ts().filterSettings.av(
128             {.isPassthrough = false});
129     filterMap[defaultAudioFilterId].monitorEventTypes =
130             android::hardware::tv::tuner::V1_1::DemuxFilterMonitorEventType::SCRAMBLING_STATUS |
131             android::hardware::tv::tuner::V1_1::DemuxFilterMonitorEventType::IP_CID_CHANGE;
132     filterMap[defaultAudioFilterId].streamType.audio(AudioStreamType::MP3);
133     // Read customized config
134     TunerTestingConfigReader1_1::readFilterConfig1_1(filterMap);
135 };
136 
137 /** Config all the dvrs that would be used in the tests */
initDvrConfig()138 inline void initDvrConfig() {
139     // Read customized config
140     TunerTestingConfigReader1_0::readDvrConfig1_0(dvrMap);
141 };
142 
143 /** Read the vendor configurations of which hardware to use for each test cases/data flows */
connectHardwaresToTestCases()144 inline void connectHardwaresToTestCases() {
145     TunerTestingConfigReader1_0::connectLiveBroadcast(live);
146     TunerTestingConfigReader1_0::connectScan(scan);
147     TunerTestingConfigReader1_0::connectDvrRecord(record);
148 };
149 
validateConnections()150 inline bool validateConnections() {
151     if (record.support && !record.hasFrontendConnection &&
152         record.dvrSourceId.compare(emptyHardwareId) == 0) {
153         ALOGW("[vts config] Record must support either a DVR source or a Frontend source.");
154         return false;
155     }
156     bool feIsValid = frontendMap.find(live.frontendId) != frontendMap.end() &&
157                      frontendMap.find(scan.frontendId) != frontendMap.end();
158     feIsValid &= record.support ? frontendMap.find(record.frontendId) != frontendMap.end() : true;
159 
160     if (!feIsValid) {
161         ALOGW("[vts config] dynamic config fe connection is invalid.");
162         return false;
163     }
164 
165     bool dvrIsValid = frontendMap[live.frontendId].config1_0.isSoftwareFe
166                               ? dvrMap.find(live.dvrSoftwareFeId) != dvrMap.end()
167                               : true;
168 
169     if (record.support) {
170         if (record.hasFrontendConnection) {
171             if (frontendMap[record.frontendId].config1_0.isSoftwareFe) {
172                 dvrIsValid &= dvrMap.find(record.dvrSoftwareFeId) != dvrMap.end();
173             }
174         } else {
175             dvrIsValid &= dvrMap.find(record.dvrSourceId) != dvrMap.end();
176         }
177         dvrIsValid &= dvrMap.find(record.dvrRecordId) != dvrMap.end();
178     }
179 
180     if (!dvrIsValid) {
181         ALOGW("[vts config] dynamic config dvr connection is invalid.");
182         return false;
183     }
184 
185     bool filterIsValid = filterMap.find(live.audioFilterId) != filterMap.end() &&
186                          filterMap.find(live.videoFilterId) != filterMap.end();
187     filterIsValid &=
188             record.support ? filterMap.find(record.recordFilterId) != filterMap.end() : true;
189 
190     if (!filterIsValid) {
191         ALOGW("[vts config] dynamic config filter connection is invalid.");
192         return false;
193     }
194 
195     return true;
196 }
197