Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 23aa3ac3 authored by shubang's avatar shubang
Browse files

Tuner service and getFrontendIds

Test: mmm; cuttlefish with tuner sample input
Change-Id: I0397c79ccf331950401e2a438f4acc48a41cc3dd
parent 3d854f4f
Loading
Loading
Loading
Loading
+73 −0
Original line number Diff line number Diff line
filegroup {
    name: "tv_tuner_aidl",
    srcs: [
        "aidl/android/media/tv/tuner/ITunerService.aidl",
    ],
    path: "aidl",
}

aidl_interface {
    name: "tv_tuner_aidl_interface",
    unstable: true,
    local_include_dir: "aidl",
    srcs: [
        ":tv_tuner_aidl",
    ],
}

cc_library {
    name: "libtunerservice",

    srcs: [
        "TunerService.cpp",
    ],

    shared_libs: [
        "android.hardware.tv.tuner@1.0",
        "libbinder",
        "libbinder_ndk",
        "libhidlbase",
        "liblog",
        "libmedia",
        "libutils",
        "tv_tuner_aidl_interface-ndk_platform",
    ],

    include_dirs: ["frameworks/av/include"],

    cflags: [
        "-Werror",
        "-Wall",
    ],

    export_include_dirs: ["."],
}


cc_binary {
    name: "mediatuner",

    srcs: [
        "main_tunerservice.cpp",
    ],

    shared_libs: [
        "android.hardware.tv.tuner@1.0",
        "libbase",
        "libbinder",
        "liblog",
        "libtunerservice",
        "libutils",
    ],

    static_libs: [
        "tv_tuner_aidl_interface-ndk_platform",
    ],

    init_rc: ["mediatuner.rc"],

    cflags: [
        "-Werror",
        "-Wall",
    ],
}
 No newline at end of file

services/tuner/OWNERS

0 → 100644
+2 −0
Original line number Diff line number Diff line
nchalko@google.com
quxiangfang@google.com
+65 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2020, 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 "TunerService"

#include <android/binder_manager.h>
#include <utils/Log.h>
#include "TunerService.h"

using ::android::hardware::hidl_vec;
using ::android::hardware::tv::tuner::V1_0::FrontendId;
using ::android::hardware::tv::tuner::V1_0::Result;

namespace android {

sp<ITuner> TunerService::mTuner;

TunerService::TunerService() {}
TunerService::~TunerService() {}

void TunerService::instantiate() {
    std::shared_ptr<TunerService> service =
            ::ndk::SharedRefBase::make<TunerService>();
    AServiceManager_addService(service->asBinder().get(), getServiceName());
}

Status TunerService::getFrontendIds(std::vector<int32_t>* ids, int32_t* /* _aidl_return */) {
    if (mTuner == nullptr) {
        // TODO: create a method for init.
        mTuner = ITuner::getService();
        if (mTuner == nullptr) {
            ALOGE("Failed to get ITuner service.");
            return ::ndk::ScopedAStatus::fromServiceSpecificError(
                    static_cast<int32_t>(Result::UNAVAILABLE));
        }
    }
    hidl_vec<FrontendId> feIds;
    Result res;
    mTuner->getFrontendIds([&](Result r, const hidl_vec<FrontendId>& frontendIds) {
        feIds = frontendIds;
        res = r;
    });
    if (res != Result::SUCCESS) {
        return ::ndk::ScopedAStatus::fromServiceSpecificError(static_cast<int32_t>(res));
    }
    ids->resize(feIds.size());
    std::copy(feIds.begin(), feIds.end(), ids->begin());

    return ::ndk::ScopedAStatus::ok();
}

} // namespace android
+44 −0
Original line number Diff line number Diff line
/**
 * Copyright (c) 2020, 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_MEDIA_TUNERSERVICE_H
#define ANDROID_MEDIA_TUNERSERVICE_H

#include <aidl/android/media/tv/tuner/BnTunerService.h>
#include <android/hardware/tv/tuner/1.0/ITuner.h>

using Status = ::ndk::ScopedAStatus;
using ::aidl::android::media::tv::tuner::BnTunerService;
using ::android::hardware::tv::tuner::V1_0::ITuner;

namespace android {

class TunerService : public BnTunerService {

public:
    static char const *getServiceName() { return "media.tuner"; }
    static void instantiate();
    TunerService();
    virtual ~TunerService();
    Status getFrontendIds(std::vector<int32_t>* ids, int32_t* _aidl_return) override;

private:
    static sp<ITuner> mTuner;
};

} // namespace android

#endif // ANDROID_MEDIA_TUNERSERVICE_H
+2 −0
Original line number Diff line number Diff line
nchalko@google.com
quxiangfang@google.com
Loading