shubang | ae56a2e | 2021-01-21 07:29:55 -0800 | [diff] [blame^] | 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 "TunerDemux" |
| 18 | |
| 19 | #include "TunerDemux.h" |
| 20 | #include "TunerFilter.h" |
| 21 | |
| 22 | using ::android::hardware::tv::tuner::V1_0::DemuxAlpFilterType; |
| 23 | using ::android::hardware::tv::tuner::V1_0::DemuxFilterMainType; |
| 24 | using ::android::hardware::tv::tuner::V1_0::DemuxFilterType; |
| 25 | using ::android::hardware::tv::tuner::V1_0::DemuxIpFilterType; |
| 26 | using ::android::hardware::tv::tuner::V1_0::DemuxMmtpFilterType; |
| 27 | using ::android::hardware::tv::tuner::V1_0::DemuxTlvFilterType; |
| 28 | using ::android::hardware::tv::tuner::V1_0::DemuxTsFilterType; |
| 29 | using ::android::hardware::tv::tuner::V1_0::Result; |
| 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | TunerDemux::TunerDemux(sp<IDemux> demux, int id) { |
| 34 | mDemux = demux; |
| 35 | mDemuxId = id; |
| 36 | } |
| 37 | |
| 38 | TunerDemux::~TunerDemux() { |
| 39 | mDemux = nullptr; |
| 40 | } |
| 41 | |
| 42 | Status TunerDemux::setFrontendDataSource(const std::shared_ptr<ITunerFrontend>& frontend) { |
| 43 | if (mDemux == nullptr) { |
| 44 | ALOGE("IDemux is not initialized"); |
| 45 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE)); |
| 46 | } |
| 47 | |
| 48 | int frontendId; |
| 49 | frontend->getFrontendId(&frontendId); |
| 50 | Result res = mDemux->setFrontendDataSource(frontendId); |
| 51 | if (res != Result::SUCCESS) { |
| 52 | return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res)); |
| 53 | } |
| 54 | return Status::ok(); |
| 55 | } |
| 56 | |
| 57 | Status TunerDemux::openFilter( |
| 58 | int type, int subType, int bufferSize, const std::shared_ptr<ITunerFilterCallback>& cb, |
| 59 | std::shared_ptr<ITunerFilter>* _aidl_return) { |
| 60 | if (mDemux == nullptr) { |
| 61 | ALOGE("IDemux is not initialized."); |
| 62 | return Status::fromServiceSpecificError(static_cast<int32_t>(Result::UNAVAILABLE)); |
| 63 | } |
| 64 | |
| 65 | DemuxFilterMainType mainType = static_cast<DemuxFilterMainType>(type); |
| 66 | DemuxFilterType filterType { |
| 67 | .mainType = mainType, |
| 68 | }; |
| 69 | |
| 70 | switch(mainType) { |
| 71 | case DemuxFilterMainType::TS: |
| 72 | filterType.subType.tsFilterType(static_cast<DemuxTsFilterType>(subType)); |
| 73 | break; |
| 74 | case DemuxFilterMainType::MMTP: |
| 75 | filterType.subType.mmtpFilterType(static_cast<DemuxMmtpFilterType>(subType)); |
| 76 | break; |
| 77 | case DemuxFilterMainType::IP: |
| 78 | filterType.subType.ipFilterType(static_cast<DemuxIpFilterType>(subType)); |
| 79 | break; |
| 80 | case DemuxFilterMainType::TLV: |
| 81 | filterType.subType.tlvFilterType(static_cast<DemuxTlvFilterType>(subType)); |
| 82 | break; |
| 83 | case DemuxFilterMainType::ALP: |
| 84 | filterType.subType.alpFilterType(static_cast<DemuxAlpFilterType>(subType)); |
| 85 | break; |
| 86 | } |
| 87 | Result status; |
| 88 | sp<IFilter> filterSp; |
| 89 | sp<IFilterCallback> cbSp = new TunerFilter::FilterCallback(cb); |
| 90 | mDemux->openFilter(filterType, bufferSize, cbSp, |
| 91 | [&](Result r, const sp<IFilter>& filter) { |
| 92 | filterSp = filter; |
| 93 | status = r; |
| 94 | }); |
| 95 | if (status != Result::SUCCESS) { |
| 96 | return Status::fromServiceSpecificError(static_cast<int32_t>(status)); |
| 97 | } |
| 98 | |
| 99 | *_aidl_return = ::ndk::SharedRefBase::make<TunerFilter>(filterSp, cbSp); |
| 100 | return Status::ok(); |
| 101 | } |
| 102 | |
| 103 | } // namespace android |