blob: f3f8a8760d2448be8420b91e9283f1ffc5dc07b0 [file] [log] [blame]
Hongguang4092f2f2021-07-08 18:49:12 -07001/*
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#pragma once
18
19#include <aidl/android/hardware/tv/tuner/BnFrontend.h>
20#include <fstream>
21#include <iostream>
Hongguang6c09bff2021-12-23 10:50:03 -080022#include <thread>
Hongguang4092f2f2021-07-08 18:49:12 -070023#include "Tuner.h"
sadiqsada56c98292023-11-02 16:45:31 -070024#include "dtv_plugin.h"
Hongguang4092f2f2021-07-08 18:49:12 -070025
26using namespace std;
27
28namespace aidl {
29namespace android {
30namespace hardware {
31namespace tv {
32namespace tuner {
33
34class Tuner;
35
sadiqsada25a0f6f2024-01-16 15:16:10 -080036const int TUNE_BUFFER_SIZE = 1; // byte
37const int TUNE_BUFFER_TIMEOUT = 2000; // ms
38
Hongguang4092f2f2021-07-08 18:49:12 -070039class Frontend : public BnFrontend {
40 public:
Hongguang4a8ac292022-08-09 14:02:03 -070041 Frontend(FrontendType type, int32_t id);
Hongguang4092f2f2021-07-08 18:49:12 -070042
43 ::ndk::ScopedAStatus setCallback(
44 const std::shared_ptr<IFrontendCallback>& in_callback) override;
45 ::ndk::ScopedAStatus tune(const FrontendSettings& in_settings) override;
46 ::ndk::ScopedAStatus stopTune() override;
47 ::ndk::ScopedAStatus close() override;
48 ::ndk::ScopedAStatus scan(const FrontendSettings& in_settings,
49 FrontendScanType in_type) override;
50 ::ndk::ScopedAStatus stopScan() override;
51 ::ndk::ScopedAStatus getStatus(const std::vector<FrontendStatusType>& in_statusTypes,
52 std::vector<FrontendStatus>* _aidl_return) override;
53 ::ndk::ScopedAStatus setLnb(int32_t in_lnbId) override;
Hongguang4092f2f2021-07-08 18:49:12 -070054 ::ndk::ScopedAStatus linkCiCam(int32_t in_ciCamId, int32_t* _aidl_return) override;
55 ::ndk::ScopedAStatus unlinkCiCam(int32_t in_ciCamId) override;
Hongguangfcedda02021-12-13 17:08:02 -080056 ::ndk::ScopedAStatus getHardwareInfo(std::string* _aidl_return) override;
Hongguange106f472022-01-11 12:09:22 -080057 ::ndk::ScopedAStatus removeOutputPid(int32_t in_pid) override;
Hongguang881190f2022-01-14 13:23:37 -080058 ::ndk::ScopedAStatus getFrontendStatusReadiness(
59 const std::vector<FrontendStatusType>& in_statusTypes,
60 std::vector<FrontendStatusReadiness>* _aidl_return) override;
Hongguang4092f2f2021-07-08 18:49:12 -070061
Hongguang2ecfc392021-11-23 10:29:15 -080062 binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
63
Hongguang4092f2f2021-07-08 18:49:12 -070064 FrontendType getFrontendType();
65 int32_t getFrontendId();
66 string getSourceFile();
sadiqsada56c98292023-11-02 16:45:31 -070067 dtv_plugin* getIptvPluginInterface();
68 string getIptvTransportDescription();
69 dtv_streamer* getIptvPluginStreamer();
sadiqsada25a0f6f2024-01-16 15:16:10 -080070 void readTuneByte(void* buf);
sadiqsadac5707a22024-01-17 09:49:23 -080071 void* getTuneByteBuffer() { return mTuneByteBuffer; };
sadiqsada25a0f6f2024-01-16 15:16:10 -080072 dtv_streamer* createIptvPluginStreamer(dtv_plugin* interface, const char* transport_desc);
73 dtv_plugin* createIptvPluginInterface();
Hongguang4092f2f2021-07-08 18:49:12 -070074 bool isLocked();
Hongguang881190f2022-01-14 13:23:37 -080075 void getFrontendInfo(FrontendInfo* _aidl_return);
Hongguang4a8ac292022-08-09 14:02:03 -070076 void setTunerService(std::shared_ptr<Tuner> tuner);
Hongguang4092f2f2021-07-08 18:49:12 -070077
78 private:
79 virtual ~Frontend();
80 bool supportsSatellite();
Hongguang6c09bff2021-12-23 10:50:03 -080081 void scanThreadLoop();
82
Hongguang4092f2f2021-07-08 18:49:12 -070083 std::shared_ptr<IFrontendCallback> mCallback;
Hongguang Chenff2c6b02021-08-07 00:12:26 +000084 std::shared_ptr<Tuner> mTuner;
Hongguang4092f2f2021-07-08 18:49:12 -070085 FrontendType mType = FrontendType::UNDEFINED;
86 int32_t mId = 0;
87 bool mIsLocked = false;
88 int32_t mCiCamId;
Hongguang6c09bff2021-12-23 10:50:03 -080089 std::thread mScanThread;
90 FrontendSettings mFrontendSettings;
91 FrontendScanType mFrontendScanType;
Hongguang4092f2f2021-07-08 18:49:12 -070092 std::ifstream mFrontendData;
Hongguang881190f2022-01-14 13:23:37 -080093 FrontendCapabilities mFrontendCaps;
94 vector<FrontendStatusType> mFrontendStatusCaps;
sadiqsada56c98292023-11-02 16:45:31 -070095 dtv_plugin* mIptvPluginInterface;
96 string mIptvTransportDescription;
97 dtv_streamer* mIptvPluginStreamer;
98 std::thread mIptvFrontendTuneThread;
sadiqsadac5707a22024-01-17 09:49:23 -080099 void* mTuneByteBuffer = nullptr;
Hongguang4092f2f2021-07-08 18:49:12 -0700100};
101
102} // namespace tuner
103} // namespace tv
104} // namespace hardware
105} // namespace android
106} // namespace aidl