/** * 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 "TunerHidlDvr" #include "TunerHidlDvr.h" #include #include #include #include #include using ::aidl::android::hardware::tv::tuner::DataFormat; using ::aidl::android::hardware::tv::tuner::PlaybackStatus; using ::aidl::android::hardware::tv::tuner::RecordStatus; using ::aidl::android::hardware::tv::tuner::Result; using ::android::unsafeHidlToAidlMQDescriptor; using ::android::hardware::MessageQueue; using ::android::hardware::MQDescriptorSync; using HidlDataFormat = ::android::hardware::tv::tuner::V1_0::DataFormat; using HidlResult = ::android::hardware::tv::tuner::V1_0::Result; using MQDesc = MQDescriptorSync; using namespace std; namespace aidl { namespace android { namespace media { namespace tv { namespace tuner { TunerHidlDvr::TunerHidlDvr(sp dvr, DvrType type) { mDvr = dvr; mType = type; } TunerHidlDvr::~TunerHidlDvr() { mDvr = nullptr; } ::ndk::ScopedAStatus TunerHidlDvr::getQueueDesc(AidlMQDesc* _aidl_return) { MQDesc dvrMQDesc; HidlResult res; mDvr->getQueueDesc([&](HidlResult r, const MQDesc& desc) { dvrMQDesc = desc; res = r; }); if (res != HidlResult::SUCCESS) { return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast(res)); } AidlMQDesc aidlMQDesc; unsafeHidlToAidlMQDescriptor(dvrMQDesc, &aidlMQDesc); *_aidl_return = std::move(aidlMQDesc); return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus TunerHidlDvr::configure(const DvrSettings& in_settings) { HidlResult res = mDvr->configure(getHidlDvrSettings(in_settings)); if (res != HidlResult::SUCCESS) { return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast(res)); } return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus TunerHidlDvr::attachFilter(const shared_ptr& in_filter) { if (in_filter == nullptr) { return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::INVALID_ARGUMENT)); } sp hidlFilter = static_cast(in_filter.get())->getHalFilter(); if (hidlFilter == nullptr) { return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::INVALID_ARGUMENT)); } HidlResult res = mDvr->attachFilter(hidlFilter); if (res != HidlResult::SUCCESS) { return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast(res)); } return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus TunerHidlDvr::detachFilter(const shared_ptr& in_filter) { if (in_filter == nullptr) { return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::INVALID_ARGUMENT)); } sp halFilter = (static_cast(in_filter.get()))->getHalFilter(); if (halFilter == nullptr) { return ::ndk::ScopedAStatus::fromServiceSpecificError( static_cast(Result::INVALID_ARGUMENT)); } HidlResult res = mDvr->detachFilter(halFilter); if (res != HidlResult::SUCCESS) { return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast(res)); } return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus TunerHidlDvr::start() { HidlResult res = mDvr->start(); if (res != HidlResult::SUCCESS) { return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast(res)); } return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus TunerHidlDvr::stop() { HidlResult res = mDvr->stop(); if (res != HidlResult::SUCCESS) { return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast(res)); } return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus TunerHidlDvr::flush() { HidlResult res = mDvr->flush(); if (res != HidlResult::SUCCESS) { return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast(res)); } return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus TunerHidlDvr::close() { HidlResult res = mDvr->close(); if (res != HidlResult::SUCCESS) { return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast(res)); } return ::ndk::ScopedAStatus::ok(); } ::ndk::ScopedAStatus TunerHidlDvr::setStatusCheckIntervalHint(int64_t /* in_milliseconds */) { HidlResult res = HidlResult::UNAVAILABLE; return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast(res)); } HidlDvrSettings TunerHidlDvr::getHidlDvrSettings(const DvrSettings& settings) { HidlDvrSettings s; switch (mType) { case DvrType::PLAYBACK: { s.playback({ .statusMask = static_cast(settings.get().statusMask), .lowThreshold = static_cast(settings.get().lowThreshold), .highThreshold = static_cast(settings.get().highThreshold), .dataFormat = static_cast( settings.get().dataFormat), .packetSize = static_cast(settings.get().packetSize), }); return s; } case DvrType::RECORD: { s.record({ .statusMask = static_cast(settings.get().statusMask), .lowThreshold = static_cast(settings.get().lowThreshold), .highThreshold = static_cast(settings.get().highThreshold), .dataFormat = static_cast(settings.get().dataFormat), .packetSize = static_cast(settings.get().packetSize), }); return s; } default: break; } return s; } /////////////// IDvrCallback /////////////////////// Return TunerHidlDvr::DvrCallback::onRecordStatus(const HidlRecordStatus status) { if (mTunerDvrCallback != nullptr) { mTunerDvrCallback->onRecordStatus(static_cast(status)); } return Void(); } Return TunerHidlDvr::DvrCallback::onPlaybackStatus(const HidlPlaybackStatus status) { if (mTunerDvrCallback != nullptr) { mTunerDvrCallback->onPlaybackStatus(static_cast(status)); } return Void(); } } // namespace tuner } // namespace tv } // namespace media } // namespace android } // namespace aidl