diff --git a/tv/tuner/1.0/default/Android.bp b/tv/tuner/1.0/default/Android.bp new file mode 100644 index 0000000000..cc8d1f50e6 --- /dev/null +++ b/tv/tuner/1.0/default/Android.bp @@ -0,0 +1,43 @@ +cc_defaults { + name: "tuner_service_defaults", + defaults: ["hidl_defaults"], + vendor: true, + relative_install_path: "hw", + srcs: [ + "Frontend.cpp", + "Tuner.cpp", + "service.cpp", + ], + + compile_multilib: "first", + + shared_libs: [ + "android.hardware.tv.tuner@1.0", + "android.hidl.memory@1.0", + "libhidlbase", + "libhidlmemory", + "libhidltransport", + "liblog", + "libstagefright_foundation", + "libutils", + ], + header_libs: [ + "media_plugin_headers", + ], +} + +cc_binary { + name: "android.hardware.tv.tuner@1.0-service", + vintf_fragments: ["android.hardware.tv.tuner@1.0-service.xml"], + defaults: ["tuner_service_defaults"], + init_rc: ["android.hardware.tv.tuner@1.0-service.rc"], +} + +cc_binary { + name: "android.hardware.tv.tuner@1.0-service-lazy", + vintf_fragments: ["android.hardware.tv.tuner@1.0-service-lazy.xml"], + overrides: ["android.hardware.tv.tuner@1.0-service"], + defaults: ["tuner_service_defaults"], + init_rc: ["android.hardware.tv.tuner@1.0-service-lazy.rc"], + cflags: ["-DLAZY_SERVICE"], +} diff --git a/tv/tuner/1.0/default/Frontend.cpp b/tv/tuner/1.0/default/Frontend.cpp new file mode 100644 index 0000000000..3dcc2b1ebd --- /dev/null +++ b/tv/tuner/1.0/default/Frontend.cpp @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2019 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 "android.hardware.tv.tuner@1.0-Frontend" + +#include "Frontend.h" +#include +#include + +namespace android { +namespace hardware { +namespace tv { +namespace tuner { +namespace V1_0 { +namespace implementation { + +Frontend::Frontend() { + // Init callback to nullptr + mCallback = nullptr; +} + +Frontend::Frontend(FrontendType type, FrontendId id) { + mType = type; + mId = id; + // Init callback to nullptr + mCallback = nullptr; +} + +Frontend::~Frontend() {} + +Return Frontend::close() { + ALOGV("%s", __FUNCTION__); + // Reset callback + mCallback = nullptr; + + return Result::SUCCESS; +} + +Return Frontend::setCallback(const sp& callback) { + ALOGV("%s", __FUNCTION__); + if (callback == nullptr) { + ALOGW("[ WARN ] Set Frontend callback with nullptr"); + return Result::INVALID_ARGUMENT; + } + + mCallback = callback; + return Result::SUCCESS; +} + +Return Frontend::tune(const FrontendSettings& /* settings */) { + ALOGV("%s", __FUNCTION__); + if (mCallback == nullptr) { + ALOGW("[ WARN ] Frontend callback is not set when tune"); + return Result::INVALID_STATE; + } + + mCallback->onEvent(FrontendEventType::NO_SIGNAL); + return Result::SUCCESS; +} + +Return Frontend::stopTune() { + ALOGV("%s", __FUNCTION__); + + return Result::SUCCESS; +} + +FrontendType Frontend::getFrontendType() { + return mType; +} + +FrontendId Frontend::getFrontendId() { + return mId; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace tuner +} // namespace tv +} // namespace hardware +} // namespace android diff --git a/tv/tuner/1.0/default/Frontend.h b/tv/tuner/1.0/default/Frontend.h new file mode 100644 index 0000000000..f77a0d8894 --- /dev/null +++ b/tv/tuner/1.0/default/Frontend.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2019 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. + */ + +#ifndef ANDROID_HARDWARE_TV_TUNER_V1_0_FRONTEND_H_ +#define ANDROID_HARDWARE_TV_TUNER_V1_0_FRONTEND_H_ + +#include +#include + +using namespace std; + +namespace android { +namespace hardware { +namespace tv { +namespace tuner { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::tv::tuner::V1_0::FrontendId; +using ::android::hardware::tv::tuner::V1_0::FrontendType; +using ::android::hardware::tv::tuner::V1_0::IFrontend; +using ::android::hardware::tv::tuner::V1_0::IFrontendCallback; +using ::android::hardware::tv::tuner::V1_0::Result; + +class Frontend : public IFrontend { + public: + Frontend(); + Frontend(FrontendType type, FrontendId id); + + virtual Return close() override; + + virtual Return setCallback(const sp& callback) override; + + virtual Return tune(const FrontendSettings& settings) override; + + virtual Return stopTune() override; + + FrontendType getFrontendType(); + + FrontendId getFrontendId(); + + private: + virtual ~Frontend(); + sp mCallback; + FrontendType mType = FrontendType::UNDEFINED; + FrontendId mId = 0; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace tuner +} // namespace tv +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_TV_TUNER_V1_0_FRONTEND_H_ diff --git a/tv/tuner/1.0/default/Tuner.cpp b/tv/tuner/1.0/default/Tuner.cpp new file mode 100644 index 0000000000..67ec754579 --- /dev/null +++ b/tv/tuner/1.0/default/Tuner.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2019 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 "android.hardware.tv.tuner@1.0-Tuner" + +#include "Tuner.h" +#include +#include +#include "Frontend.h" + +namespace android { +namespace hardware { +namespace tv { +namespace tuner { +namespace V1_0 { +namespace implementation { + +Tuner::Tuner() { + // Static Frontends array to maintain local frontends information + // Array index matches their FrontendId in the default impl + mFrontendSize = 8; + mFrontends.resize(mFrontendSize); + mFrontends[0] = new Frontend(); + mFrontends[1] = new Frontend(FrontendType::ATSC, 1); + mFrontends[2] = new Frontend(FrontendType::DVBC, 2); + mFrontends[3] = new Frontend(FrontendType::DVBS, 3); + mFrontends[4] = new Frontend(FrontendType::DVBT, 4); + mFrontends[5] = new Frontend(FrontendType::ISDBT, 5); + mFrontends[6] = new Frontend(FrontendType::ANALOG, 6); + mFrontends[7] = new Frontend(FrontendType::ATSC, 7); +} + +Tuner::~Tuner() {} + +Return Tuner::getFrontendIds(getFrontendIds_cb _hidl_cb) { + ALOGV("%s", __FUNCTION__); + + vector frontendIds; + frontendIds.resize(mFrontendSize); + for (int i = 0; i < mFrontendSize; i++) { + frontendIds[i] = mFrontends[i]->getFrontendId(); + } + + _hidl_cb(Result::SUCCESS, frontendIds); + return Void(); +} + +Return Tuner::openFrontendById(uint32_t frontendId, openFrontendById_cb _hidl_cb) { + ALOGV("%s", __FUNCTION__); + + if (frontendId >= mFrontendSize || frontendId < 0) { + ALOGW("[ WARN ] Frontend with id %d isn't available", frontendId); + _hidl_cb(Result::UNAVAILABLE, nullptr); + return Void(); + } + + _hidl_cb(Result::SUCCESS, mFrontends[frontendId]); + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace tuner +} // namespace tv +} // namespace hardware +} // namespace android diff --git a/tv/tuner/1.0/default/Tuner.h b/tv/tuner/1.0/default/Tuner.h new file mode 100644 index 0000000000..2152c899c8 --- /dev/null +++ b/tv/tuner/1.0/default/Tuner.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 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. + */ + +#ifndef ANDROID_HARDWARE_TV_TUNER_V1_0_TUNER_H_ +#define ANDROID_HARDWARE_TV_TUNER_V1_0_TUNER_H_ + +#include +#include "Frontend.h" + +using namespace std; + +namespace android { +namespace hardware { +namespace tv { +namespace tuner { +namespace V1_0 { +namespace implementation { + +class Tuner : public ITuner { + public: + Tuner(); + virtual Return getFrontendIds(getFrontendIds_cb _hidl_cb) override; + + virtual Return openFrontendById(uint32_t frontendId, + openFrontendById_cb _hidl_cb) override; + + private: + virtual ~Tuner(); + // Static mFrontends array to maintain local frontends information + vector> mFrontends; + // To maintain how many Frontends we have + int mFrontendSize; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace tuner +} // namespace tv +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_TV_TUNER_V1_0_TUNER_H_ diff --git a/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service-lazy.rc b/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service-lazy.rc new file mode 100644 index 0000000000..ad72fae706 --- /dev/null +++ b/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service-lazy.rc @@ -0,0 +1,9 @@ +service vendor.tuner-hal-1-0 /vendor/bin/hw/android.hardware.tv.tuner@1.0-service-lazy + interface android.hardware.tv.tuner@1.0::ITuner default + oneshot + disabled + class hal + user media + group mediadrm drmrpc + ioprio rt 4 + writepid /dev/cpuset/foreground/tasks \ No newline at end of file diff --git a/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service-lazy.xml b/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service-lazy.xml new file mode 100644 index 0000000000..4bcfe10685 --- /dev/null +++ b/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service-lazy.xml @@ -0,0 +1,11 @@ + + + android.hardware.tv.tuner + hwbinder + 1.0 + + ITuner + default + + + \ No newline at end of file diff --git a/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service.rc b/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service.rc new file mode 100644 index 0000000000..6d59ed75bb --- /dev/null +++ b/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service.rc @@ -0,0 +1,6 @@ +service vendor.tuner-hal-1-0 /vendor/bin/hw/android.hardware.tv.tuner@1.0-service + class hal + user media + group mediadrm drmrpc + ioprio rt 4 + writepid /dev/cpuset/foreground/tasks \ No newline at end of file diff --git a/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service.xml b/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service.xml new file mode 100644 index 0000000000..4bcfe10685 --- /dev/null +++ b/tv/tuner/1.0/default/android.hardware.tv.tuner@1.0-service.xml @@ -0,0 +1,11 @@ + + + android.hardware.tv.tuner + hwbinder + 1.0 + + ITuner + default + + + \ No newline at end of file diff --git a/tv/tuner/1.0/default/service.cpp b/tv/tuner/1.0/default/service.cpp new file mode 100644 index 0000000000..581d269b9e --- /dev/null +++ b/tv/tuner/1.0/default/service.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2019 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_NDEBUG 0 +#ifdef LAZY_SERVICE +#define LOG_TAG "android.hardware.tv.tuner@1.0-service-lazy" +#else +#define LOG_TAG "android.hardware.tv.tuner@1.0-service" +#endif + +#include +#include +#include + +#include "Tuner.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::hardware::LazyServiceRegistrar; +using android::hardware::tv::tuner::V1_0::ITuner; +using android::hardware::tv::tuner::V1_0::implementation::Tuner; + +#ifdef LAZY_SERVICE +const bool kLazyService = true; +#else +const bool kLazyService = false; +#endif + +int main() { + configureRpcThreadpool(8, true /* callerWillJoin */); + + // Setup hwbinder service + android::sp service = new Tuner(); + android::status_t status; + if (kLazyService) { + auto serviceRegistrar = std::make_shared(); + status = serviceRegistrar->registerService(service); + } else { + status = service->registerAsService(); + } + LOG_ALWAYS_FATAL_IF(status != android::OK, "Error while registering tuner service: %d", status); + + joinRpcThreadpool(); + return 0; +}