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 "TunerDvr" 18 19 #include "TunerDvr.h" 20 21 #include <aidl/android/hardware/tv/tuner/Result.h> 22 #include <utils/Log.h> 23 24 #include "TunerFilter.h" 25 26 using ::aidl::android::hardware::tv::tuner::Result; 27 28 namespace aidl { 29 namespace android { 30 namespace media { 31 namespace tv { 32 namespace tuner { 33 TunerDvr(shared_ptr<IDvr> dvr,DvrType type)34TunerDvr::TunerDvr(shared_ptr<IDvr> dvr, DvrType type) { 35 mDvr = dvr; 36 mType = type; 37 } 38 ~TunerDvr()39TunerDvr::~TunerDvr() { 40 mDvr = nullptr; 41 } 42 getQueueDesc(AidlMQDesc * _aidl_return)43::ndk::ScopedAStatus TunerDvr::getQueueDesc(AidlMQDesc* _aidl_return) { 44 if (mDvr == nullptr) { 45 ALOGE("IDvr is not initialized"); 46 return ::ndk::ScopedAStatus::fromServiceSpecificError( 47 static_cast<int32_t>(Result::UNAVAILABLE)); 48 } 49 50 return mDvr->getQueueDesc(_aidl_return); 51 } 52 configure(const DvrSettings & in_settings)53::ndk::ScopedAStatus TunerDvr::configure(const DvrSettings& in_settings) { 54 if (mDvr == nullptr) { 55 ALOGE("IDvr is not initialized"); 56 return ::ndk::ScopedAStatus::fromServiceSpecificError( 57 static_cast<int32_t>(Result::UNAVAILABLE)); 58 } 59 60 return mDvr->configure(in_settings); 61 } 62 attachFilter(const shared_ptr<ITunerFilter> & in_filter)63::ndk::ScopedAStatus TunerDvr::attachFilter(const shared_ptr<ITunerFilter>& in_filter) { 64 if (mDvr == nullptr) { 65 ALOGE("IDvr is not initialized"); 66 return ::ndk::ScopedAStatus::fromServiceSpecificError( 67 static_cast<int32_t>(Result::UNAVAILABLE)); 68 } 69 70 if (in_filter == nullptr) { 71 return ::ndk::ScopedAStatus::fromServiceSpecificError( 72 static_cast<int32_t>(Result::INVALID_ARGUMENT)); 73 } 74 75 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(in_filter.get()))->getHalFilter(); 76 if (halFilter == nullptr) { 77 return ::ndk::ScopedAStatus::fromServiceSpecificError( 78 static_cast<int32_t>(Result::INVALID_ARGUMENT)); 79 } 80 81 return mDvr->attachFilter(halFilter); 82 } 83 detachFilter(const shared_ptr<ITunerFilter> & in_filter)84::ndk::ScopedAStatus TunerDvr::detachFilter(const shared_ptr<ITunerFilter>& in_filter) { 85 if (mDvr == nullptr) { 86 ALOGE("IDvr is not initialized"); 87 return ::ndk::ScopedAStatus::fromServiceSpecificError( 88 static_cast<int32_t>(Result::UNAVAILABLE)); 89 } 90 91 if (in_filter == nullptr) { 92 return ::ndk::ScopedAStatus::fromServiceSpecificError( 93 static_cast<int32_t>(Result::INVALID_ARGUMENT)); 94 } 95 96 shared_ptr<IFilter> halFilter = (static_cast<TunerFilter*>(in_filter.get()))->getHalFilter(); 97 if (halFilter == nullptr) { 98 return ::ndk::ScopedAStatus::fromServiceSpecificError( 99 static_cast<int32_t>(Result::INVALID_ARGUMENT)); 100 } 101 102 return mDvr->detachFilter(halFilter); 103 } 104 start()105::ndk::ScopedAStatus TunerDvr::start() { 106 if (mDvr == nullptr) { 107 ALOGE("IDvr is not initialized"); 108 return ::ndk::ScopedAStatus::fromServiceSpecificError( 109 static_cast<int32_t>(Result::UNAVAILABLE)); 110 } 111 112 return mDvr->start(); 113 } 114 stop()115::ndk::ScopedAStatus TunerDvr::stop() { 116 if (mDvr == nullptr) { 117 ALOGE("IDvr is not initialized"); 118 return ::ndk::ScopedAStatus::fromServiceSpecificError( 119 static_cast<int32_t>(Result::UNAVAILABLE)); 120 } 121 122 return mDvr->stop(); 123 } 124 flush()125::ndk::ScopedAStatus TunerDvr::flush() { 126 if (mDvr == nullptr) { 127 ALOGE("IDvr is not initialized"); 128 return ::ndk::ScopedAStatus::fromServiceSpecificError( 129 static_cast<int32_t>(Result::UNAVAILABLE)); 130 } 131 132 return mDvr->flush(); 133 } 134 close()135::ndk::ScopedAStatus TunerDvr::close() { 136 if (mDvr == nullptr) { 137 ALOGE("IDvr is not initialized"); 138 return ::ndk::ScopedAStatus::fromServiceSpecificError( 139 static_cast<int32_t>(Result::UNAVAILABLE)); 140 } 141 142 auto status = mDvr->close(); 143 mDvr = nullptr; 144 145 return status; 146 } 147 148 /////////////// IDvrCallback /////////////////////// onRecordStatus(const RecordStatus status)149::ndk::ScopedAStatus TunerDvr::DvrCallback::onRecordStatus(const RecordStatus status) { 150 if (mTunerDvrCallback != nullptr) { 151 mTunerDvrCallback->onRecordStatus(status); 152 } 153 return ndk::ScopedAStatus::ok(); 154 } 155 onPlaybackStatus(const PlaybackStatus status)156::ndk::ScopedAStatus TunerDvr::DvrCallback::onPlaybackStatus(const PlaybackStatus status) { 157 if (mTunerDvrCallback != nullptr) { 158 mTunerDvrCallback->onPlaybackStatus(status); 159 } 160 return ndk::ScopedAStatus::ok(); 161 } 162 163 } // namespace tuner 164 } // namespace tv 165 } // namespace media 166 } // namespace android 167 } // namespace aidl 168