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