/** * Copyright 2021, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "TunerDemux" #include "TunerDemux.h" #include #include #include #include #include #include #include "TunerDvr.h" #include "TunerTimeFilter.h" using ::aidl::android::hardware::tv::tuner::IDvr; using ::aidl::android::hardware::tv::tuner::IDvrCallback; using ::aidl::android::hardware::tv::tuner::IFilter; using ::aidl::android::hardware::tv::tuner::IFilterCallback; using ::aidl::android::hardware::tv::tuner::ITimeFilter; using ::aidl::android::hardware::tv::tuner::Result; namespace aidl { namespace android { namespace media { namespace tv { namespace tuner { TunerDemux::TunerDemux(shared_ptr demux, int id) { mDemux = demux; mDemuxId = id; } TunerDemux::~TunerDemux() { mDemux = nullptr; } ::ndk::ScopedAStatus TunerDemux::setFrontendDataSource( const shared_ptr& in_frontend) { if (mDemux == nullptr) { ALOGE("IDemux is not initialized"); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } int frontendId; in_frontend->getFrontendId(&frontendId); return mDemux->setFrontendDataSource(frontendId); } ::ndk::ScopedAStatus TunerDemux::setFrontendDataSourceById(int frontendId) { if (mDemux == nullptr) { ALOGE("IDemux is not initialized"); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } return mDemux->setFrontendDataSource(frontendId); } ::ndk::ScopedAStatus TunerDemux::openFilter(const DemuxFilterType& in_type, int32_t in_bufferSize, const shared_ptr& in_cb, shared_ptr* _aidl_return) { if (mDemux == nullptr) { ALOGE("IDemux is not initialized"); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } shared_ptr filter; shared_ptr filterCb = ::ndk::SharedRefBase::make(in_cb); shared_ptr cb = filterCb; auto status = mDemux->openFilter(in_type, in_bufferSize, cb, &filter); if (status.isOk()) { *_aidl_return = ::ndk::SharedRefBase::make(filter, filterCb, in_type); } return status; } ::ndk::ScopedAStatus TunerDemux::openTimeFilter(shared_ptr* _aidl_return) { if (mDemux == nullptr) { ALOGE("IDemux is not initialized."); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } shared_ptr filter; auto status = mDemux->openTimeFilter(&filter); if (status.isOk()) { *_aidl_return = ::ndk::SharedRefBase::make(filter); } return status; } ::ndk::ScopedAStatus TunerDemux::getAvSyncHwId(const shared_ptr& tunerFilter, int32_t* _aidl_return) { if (mDemux == nullptr) { ALOGE("IDemux is not initialized."); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } shared_ptr halFilter = (static_cast(tunerFilter.get()))->getHalFilter(); return mDemux->getAvSyncHwId(halFilter, _aidl_return); } ::ndk::ScopedAStatus TunerDemux::getAvSyncTime(int32_t avSyncHwId, int64_t* _aidl_return) { if (mDemux == nullptr) { ALOGE("IDemux is not initialized."); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } return mDemux->getAvSyncTime(avSyncHwId, _aidl_return); } ::ndk::ScopedAStatus TunerDemux::openDvr(DvrType in_dvbType, int32_t in_bufferSize, const shared_ptr& in_cb, shared_ptr* _aidl_return) { if (mDemux == nullptr) { ALOGE("IDemux is not initialized."); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } shared_ptr callback = ::ndk::SharedRefBase::make(in_cb); shared_ptr halDvr; auto res = mDemux->openDvr(in_dvbType, in_bufferSize, callback, &halDvr); if (res.isOk()) { *_aidl_return = ::ndk::SharedRefBase::make(halDvr, in_dvbType); } return res; } ::ndk::ScopedAStatus TunerDemux::connectCiCam(int32_t ciCamId) { if (mDemux == nullptr) { ALOGE("IDemux is not initialized."); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } return mDemux->connectCiCam(ciCamId); } ::ndk::ScopedAStatus TunerDemux::disconnectCiCam() { if (mDemux == nullptr) { ALOGE("IDemux is not initialized."); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } return mDemux->disconnectCiCam(); } ::ndk::ScopedAStatus TunerDemux::close() { if (mDemux == nullptr) { ALOGE("IDemux is not initialized."); return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::UNAVAILABLE)); } auto res = mDemux->close(); mDemux = nullptr; return res; } } // namespace tuner } // namespace tv } // namespace media } // namespace android } // namespace aidl