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 #define LOG_TAG "DescramblerClient"
18
19 #include <android-base/logging.h>
20 #include <utils/Log.h>
21
22 #include "DescramblerClient.h"
23
24 namespace android {
25
26 /////////////// DescramblerClient ///////////////////////
DescramblerClient(shared_ptr<ITunerDescrambler> tunerDescrambler)27 DescramblerClient::DescramblerClient(shared_ptr<ITunerDescrambler> tunerDescrambler) {
28 mTunerDescrambler = tunerDescrambler;
29 }
30
~DescramblerClient()31 DescramblerClient::~DescramblerClient() {
32 mTunerDescrambler = nullptr;
33 }
34
setDemuxSource(sp<DemuxClient> demuxClient)35 Result DescramblerClient::setDemuxSource(sp<DemuxClient> demuxClient) {
36 if (demuxClient == nullptr) {
37 return Result::INVALID_ARGUMENT;
38 }
39
40 if (mTunerDescrambler != nullptr) {
41 Status s = mTunerDescrambler->setDemuxSource(demuxClient->getAidlDemux());
42 return ClientHelper::getServiceSpecificErrorCode(s);
43 }
44
45 return Result::INVALID_STATE;
46 }
47
setKeyToken(vector<uint8_t> keyToken)48 Result DescramblerClient::setKeyToken(vector<uint8_t> keyToken) {
49 if (mTunerDescrambler != nullptr) {
50 Status s = mTunerDescrambler->setKeyToken(keyToken);
51 return ClientHelper::getServiceSpecificErrorCode(s);
52 }
53
54 return Result::INVALID_STATE;
55 }
56
addPid(DemuxPid pid,sp<FilterClient> optionalSourceFilter)57 Result DescramblerClient::addPid(DemuxPid pid, sp<FilterClient> optionalSourceFilter) {
58 if (mTunerDescrambler != nullptr) {
59 shared_ptr<ITunerFilter> aidlFilter =
60 (optionalSourceFilter == nullptr) ? nullptr : optionalSourceFilter->getAidlFilter();
61 Status s = mTunerDescrambler->addPid(pid, aidlFilter);
62 return ClientHelper::getServiceSpecificErrorCode(s);
63 }
64
65 return Result::INVALID_STATE;
66 }
67
removePid(DemuxPid pid,sp<FilterClient> optionalSourceFilter)68 Result DescramblerClient::removePid(DemuxPid pid, sp<FilterClient> optionalSourceFilter) {
69 if (mTunerDescrambler != nullptr) {
70 shared_ptr<ITunerFilter> aidlFilter =
71 (optionalSourceFilter == nullptr) ? nullptr : optionalSourceFilter->getAidlFilter();
72 Status s = mTunerDescrambler->removePid(pid, aidlFilter);
73 return ClientHelper::getServiceSpecificErrorCode(s);
74 }
75
76 return Result::INVALID_STATE;
77 }
78
close()79 Result DescramblerClient::close() {
80 if (mTunerDescrambler != nullptr) {
81 Status s = mTunerDescrambler->close();
82 mTunerDescrambler = nullptr;
83 return ClientHelper::getServiceSpecificErrorCode(s);
84 }
85
86 return Result::INVALID_STATE;
87 }
88
89 } // namespace android
90