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 "TunerHidlDescrambler"
18
19 #include "TunerHidlDescrambler.h"
20
21 #include <aidl/android/hardware/tv/tuner/Result.h>
22
23 #include "TunerHidlDemux.h"
24 #include "TunerHidlFilter.h"
25
26 using ::aidl::android::hardware::tv::tuner::Result;
27
28 using HidlResult = ::android::hardware::tv::tuner::V1_0::Result;
29
30 using namespace std;
31
32 namespace aidl {
33 namespace android {
34 namespace media {
35 namespace tv {
36 namespace tuner {
37
TunerHidlDescrambler(sp<HidlIDescrambler> descrambler)38 TunerHidlDescrambler::TunerHidlDescrambler(sp<HidlIDescrambler> descrambler) {
39 mDescrambler = descrambler;
40 }
41
~TunerHidlDescrambler()42 TunerHidlDescrambler::~TunerHidlDescrambler() {
43 mDescrambler = nullptr;
44 }
45
setDemuxSource(const shared_ptr<ITunerDemux> & in_tunerDemux)46 ::ndk::ScopedAStatus TunerHidlDescrambler::setDemuxSource(
47 const shared_ptr<ITunerDemux>& in_tunerDemux) {
48 HidlResult res = mDescrambler->setDemuxSource(
49 static_cast<TunerHidlDemux*>(in_tunerDemux.get())->getId());
50 if (res != HidlResult::SUCCESS) {
51 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
52 }
53 return ::ndk::ScopedAStatus::ok();
54 }
55
setKeyToken(const vector<uint8_t> & in_keyToken)56 ::ndk::ScopedAStatus TunerHidlDescrambler::setKeyToken(const vector<uint8_t>& in_keyToken) {
57 HidlResult res = mDescrambler->setKeyToken(in_keyToken);
58 if (res != HidlResult::SUCCESS) {
59 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
60 }
61 return ::ndk::ScopedAStatus::ok();
62 }
63
addPid(const DemuxPid & in_pid,const shared_ptr<ITunerFilter> & in_optionalSourceFilter)64 ::ndk::ScopedAStatus TunerHidlDescrambler::addPid(
65 const DemuxPid& in_pid, const shared_ptr<ITunerFilter>& in_optionalSourceFilter) {
66 sp<HidlIFilter> halFilter =
67 (in_optionalSourceFilter == nullptr)
68 ? nullptr
69 : static_cast<TunerHidlFilter*>(in_optionalSourceFilter.get())->getHalFilter();
70 HidlResult res = mDescrambler->addPid(getHidlDemuxPid(in_pid), halFilter);
71 if (res != HidlResult::SUCCESS) {
72 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
73 }
74 return ::ndk::ScopedAStatus::ok();
75 }
76
removePid(const DemuxPid & in_pid,const shared_ptr<ITunerFilter> & in_optionalSourceFilter)77 ::ndk::ScopedAStatus TunerHidlDescrambler::removePid(
78 const DemuxPid& in_pid, const shared_ptr<ITunerFilter>& in_optionalSourceFilter) {
79 sp<HidlIFilter> halFilter =
80 (in_optionalSourceFilter == nullptr)
81 ? nullptr
82 : static_cast<TunerHidlFilter*>(in_optionalSourceFilter.get())->getHalFilter();
83 HidlResult res = mDescrambler->removePid(getHidlDemuxPid(in_pid), halFilter);
84 if (res != HidlResult::SUCCESS) {
85 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
86 }
87 return ::ndk::ScopedAStatus::ok();
88 }
89
close()90 ::ndk::ScopedAStatus TunerHidlDescrambler::close() {
91 HidlResult res = mDescrambler->close();
92 if (res != HidlResult::SUCCESS) {
93 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
94 }
95 return ::ndk::ScopedAStatus::ok();
96 }
97
getHidlDemuxPid(const DemuxPid & pid)98 HidlDemuxPid TunerHidlDescrambler::getHidlDemuxPid(const DemuxPid& pid) {
99 HidlDemuxPid hidlPid;
100 switch (pid.getTag()) {
101 case DemuxPid::tPid: {
102 hidlPid.tPid((uint16_t)pid.get<DemuxPid::Tag::tPid>());
103 break;
104 }
105 case DemuxPid::mmtpPid: {
106 hidlPid.mmtpPid((uint16_t)pid.get<DemuxPid::Tag::mmtpPid>());
107 break;
108 }
109 }
110 return hidlPid;
111 }
112
113 } // namespace tuner
114 } // namespace tv
115 } // namespace media
116 } // namespace android
117 } // namespace aidl
118