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 "DemuxTests.h"
18 
openDemux(sp<IDemux> & demux,uint32_t & demuxId)19 AssertionResult DemuxTests::openDemux(sp<IDemux>& demux, uint32_t& demuxId) {
20     Result status;
21     mService->openDemux([&](Result result, uint32_t id, const sp<IDemux>& demuxSp) {
22         mDemux = demuxSp;
23         demux = demuxSp;
24         demuxId = id;
25         status = result;
26     });
27     return AssertionResult(status == Result::SUCCESS);
28 }
29 
setDemuxFrontendDataSource(uint32_t frontendId)30 AssertionResult DemuxTests::setDemuxFrontendDataSource(uint32_t frontendId) {
31     EXPECT_TRUE(mDemux) << "Test with openDemux first.";
32     auto status = mDemux->setFrontendDataSource(frontendId);
33     return AssertionResult(status.isOk());
34 }
35 
getDemuxCaps(DemuxCapabilities & demuxCaps)36 AssertionResult DemuxTests::getDemuxCaps(DemuxCapabilities& demuxCaps) {
37     if (!mDemux) {
38         ALOGW("[vts] Test with openDemux first.");
39         return failure();
40     }
41     Result status;
42     mService->getDemuxCaps([&](Result result, DemuxCapabilities caps) {
43         status = result;
44         demuxCaps = caps;
45     });
46     return AssertionResult(status == Result::SUCCESS);
47 }
48 
closeDemux()49 AssertionResult DemuxTests::closeDemux() {
50     EXPECT_TRUE(mDemux) << "Test with openDemux first.";
51     auto status = mDemux->close();
52     mDemux = nullptr;
53     return AssertionResult(status.isOk());
54 }
55 
getAvSyncId(sp<IFilter> filter,uint32_t & avSyncHwId)56 AssertionResult DemuxTests::getAvSyncId(sp<IFilter> filter, uint32_t& avSyncHwId) {
57     EXPECT_TRUE(mDemux) << "Demux is not opened yet.";
58     Result status;
59     mDemux->getAvSyncHwId(filter, [&](Result result, uint32_t id) {
60         status = result;
61         avSyncHwId = id;
62     });
63     return AssertionResult(status == Result::SUCCESS);
64 }
65 
getAvSyncTime(uint32_t avSyncId)66 AssertionResult DemuxTests::getAvSyncTime(uint32_t avSyncId) {
67     EXPECT_TRUE(mDemux) << "Demux is not opened yet.";
68     Result status;
69     uint64_t syncTime;
70     mDemux->getAvSyncTime(avSyncId, [&](Result result, uint64_t time) {
71         status = result;
72         syncTime = time;
73     });
74     return AssertionResult(status == Result::SUCCESS);
75 }