blob: 51b7edeb128223bc761e6c4fdcb34273ea22817c [file] [log] [blame]
Hongguang093c5f32021-08-09 19:46:34 -07001/**
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
26using ::aidl::android::hardware::tv::tuner::Result;
27
28using HidlResult = ::android::hardware::tv::tuner::V1_0::Result;
29
30using namespace std;
31
32namespace aidl {
33namespace android {
34namespace media {
35namespace tv {
36namespace tuner {
37
38TunerHidlDescrambler::TunerHidlDescrambler(sp<HidlIDescrambler> descrambler) {
39 mDescrambler = descrambler;
40}
41
42TunerHidlDescrambler::~TunerHidlDescrambler() {
43 mDescrambler = nullptr;
44}
45
46::ndk::ScopedAStatus TunerHidlDescrambler::setDemuxSource(
47 const shared_ptr<ITunerDemux>& in_tunerDemux) {
Hongguang093c5f32021-08-09 19:46:34 -070048 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
56::ndk::ScopedAStatus TunerHidlDescrambler::setKeyToken(const vector<uint8_t>& in_keyToken) {
Hongguang093c5f32021-08-09 19:46:34 -070057 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
64::ndk::ScopedAStatus TunerHidlDescrambler::addPid(
65 const DemuxPid& in_pid, const shared_ptr<ITunerFilter>& in_optionalSourceFilter) {
Hongguang093c5f32021-08-09 19:46:34 -070066 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
77::ndk::ScopedAStatus TunerHidlDescrambler::removePid(
78 const DemuxPid& in_pid, const shared_ptr<ITunerFilter>& in_optionalSourceFilter) {
Hongguang093c5f32021-08-09 19:46:34 -070079 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
90::ndk::ScopedAStatus TunerHidlDescrambler::close() {
Hongguang093c5f32021-08-09 19:46:34 -070091 HidlResult res = mDescrambler->close();
Hongguang093c5f32021-08-09 19:46:34 -070092 if (res != HidlResult::SUCCESS) {
93 return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
94 }
95 return ::ndk::ScopedAStatus::ok();
96}
97
98HidlDemuxPid 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