| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef _ANDROID_MEDIA_TV_TUNER_H_ |
| 18 |
#define _ANDROID_MEDIA_TV_TUNER_H_ |
| 19 |
|
| 20 |
#include <C2BlockInternal.h> |
| 21 |
#include <C2HandleIonInternal.h> |
| 22 |
#include <C2ParamDef.h> |
| 23 |
#include <aidl/android/hardware/tv/tuner/DemuxFilterEvent.h> |
| 24 |
#include <aidl/android/hardware/tv/tuner/DemuxFilterMonitorEvent.h> |
| 25 |
#include <aidl/android/hardware/tv/tuner/DemuxFilterStatus.h> |
| 26 |
#include <aidl/android/hardware/tv/tuner/DemuxFilterType.h> |
| 27 |
#include <aidl/android/hardware/tv/tuner/DemuxPid.h> |
| 28 |
#include <aidl/android/hardware/tv/tuner/DvrType.h> |
| 29 |
#include <aidl/android/hardware/tv/tuner/FrontendCapabilities.h> |
| 30 |
#include <aidl/android/hardware/tv/tuner/FrontendEventType.h> |
| 31 |
#include <aidl/android/hardware/tv/tuner/FrontendInfo.h> |
| 32 |
#include <aidl/android/hardware/tv/tuner/FrontendScanMessage.h> |
| 33 |
#include <aidl/android/hardware/tv/tuner/FrontendScanMessageType.h> |
| 34 |
#include <aidl/android/hardware/tv/tuner/FrontendScanType.h> |
| 35 |
#include <aidl/android/hardware/tv/tuner/FrontendSettings.h> |
| 36 |
#include <aidl/android/hardware/tv/tuner/LnbEventType.h> |
| 37 |
#include <aidl/android/hardware/tv/tuner/PlaybackStatus.h> |
| 38 |
#include <aidl/android/hardware/tv/tuner/RecordStatus.h> |
| 39 |
#include <aidl/android/hardware/tv/tuner/Result.h> |
| 40 |
#include <fmq/AidlMessageQueue.h> |
| 41 |
#include <utils/Mutex.h> |
| 42 |
#include <utils/RefBase.h> |
| 43 |
|
| 44 |
#include <fstream> |
| 45 |
#include <string> |
| 46 |
#include <unordered_map> |
| 47 |
|
| 48 |
#include "jni.h" |
| 49 |
#include "tuner/DemuxClient.h" |
| 50 |
#include "tuner/DescramblerClient.h" |
| 51 |
#include "tuner/FilterClient.h" |
| 52 |
#include "tuner/FilterClientCallback.h" |
| 53 |
#include "tuner/FrontendClient.h" |
| 54 |
#include "tuner/FrontendClientCallback.h" |
| 55 |
#include "tuner/LnbClient.h" |
| 56 |
#include "tuner/LnbClientCallback.h" |
| 57 |
#include "tuner/TimeFilterClient.h" |
| 58 |
#include "tuner/TunerClient.h" |
| 59 |
|
| 60 |
using ::aidl::android::hardware::common::fmq::MQDescriptor; |
| 61 |
using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite; |
| 62 |
using ::aidl::android::hardware::tv::tuner::DemuxFilterEvent; |
| 63 |
using ::aidl::android::hardware::tv::tuner::DemuxFilterMonitorEvent; |
| 64 |
using ::aidl::android::hardware::tv::tuner::DemuxFilterStatus; |
| 65 |
using ::aidl::android::hardware::tv::tuner::DemuxFilterType; |
| 66 |
using ::aidl::android::hardware::tv::tuner::DemuxPid; |
| 67 |
using ::aidl::android::hardware::tv::tuner::DvrType; |
| 68 |
using ::aidl::android::hardware::tv::tuner::FrontendCapabilities; |
| 69 |
using ::aidl::android::hardware::tv::tuner::FrontendEventType; |
| 70 |
using ::aidl::android::hardware::tv::tuner::FrontendInfo; |
| 71 |
using ::aidl::android::hardware::tv::tuner::FrontendScanMessage; |
| 72 |
using ::aidl::android::hardware::tv::tuner::FrontendScanMessageType; |
| 73 |
using ::aidl::android::hardware::tv::tuner::FrontendScanType; |
| 74 |
using ::aidl::android::hardware::tv::tuner::FrontendSettings; |
| 75 |
using ::aidl::android::hardware::tv::tuner::LnbEventType; |
| 76 |
using ::aidl::android::hardware::tv::tuner::PlaybackStatus; |
| 77 |
using ::aidl::android::hardware::tv::tuner::RecordStatus; |
| 78 |
using ::aidl::android::hardware::tv::tuner::Result; |
| 79 |
using ::android::hardware::EventFlag; |
| 80 |
|
| 81 |
using MQ = MQDescriptor<int8_t, SynchronizedReadWrite>; |
| 82 |
|
| 83 |
namespace android { |
| 84 |
|
| 85 |
struct LnbClientCallbackImpl : public LnbClientCallback { |
| 86 |
~LnbClientCallbackImpl(); |
| 87 |
virtual void onEvent(LnbEventType lnbEventType); |
| 88 |
virtual void onDiseqcMessage(const vector<uint8_t>& diseqcMessage); |
| 89 |
|
| 90 |
void setLnb(jweak lnbObj); |
| 91 |
private: |
| 92 |
jweak mLnbObj; |
| 93 |
}; |
| 94 |
|
| 95 |
struct DvrClientCallbackImpl : public DvrClientCallback { |
| 96 |
~DvrClientCallbackImpl(); |
| 97 |
virtual void onRecordStatus(RecordStatus status); |
| 98 |
virtual void onPlaybackStatus(PlaybackStatus status); |
| 99 |
|
| 100 |
void setDvr(jweak dvrObj); |
| 101 |
private: |
| 102 |
jweak mDvrObj; |
| 103 |
}; |
| 104 |
|
| 105 |
struct MediaEvent : public RefBase { |
| 106 |
MediaEvent(sp<FilterClient> filterClient, native_handle_t* avHandle, int64_t dataId, |
| 107 |
int64_t dataSize, jobject obj); |
| 108 |
~MediaEvent(); |
| 109 |
jobject getLinearBlock(); |
| 110 |
int64_t getAudioHandle(); |
| 111 |
void finalize(); |
| 112 |
|
| 113 |
sp<FilterClient> mFilterClient; |
| 114 |
native_handle_t* mAvHandle; |
| 115 |
int64_t mDataId; |
| 116 |
int64_t mDataSize; |
| 117 |
uint8_t* mBuffer; |
| 118 |
android::Mutex mLock; |
| 119 |
int mDataIdRefCnt; |
| 120 |
int mAvHandleRefCnt; |
| 121 |
jweak mMediaEventObj; |
| 122 |
jweak mLinearBlockObj; |
| 123 |
C2HandleIon* mIonHandle; |
| 124 |
std::weak_ptr<C2Buffer> mC2Buffer; |
| 125 |
}; |
| 126 |
|
| 127 |
struct FilterClientCallbackImpl : public FilterClientCallback { |
| 128 |
~FilterClientCallbackImpl(); |
| 129 |
virtual void onFilterEvent(const vector<DemuxFilterEvent>& events); |
| 130 |
virtual void onFilterStatus(const DemuxFilterStatus status); |
| 131 |
|
| 132 |
void setFilter(jweak filterObj, sp<FilterClient> filterClient); |
| 133 |
void setSharedFilter(jweak filterObj, sp<FilterClient> filterClient); |
| 134 |
|
| 135 |
private: |
| 136 |
jweak mFilterObj; |
| 137 |
sp<FilterClient> mFilterClient; |
| 138 |
bool mSharedFilter; |
| 139 |
void getSectionEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 140 |
void getMediaEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 141 |
void getPesEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 142 |
void getTsRecordEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 143 |
void getMmtpRecordEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 144 |
void getDownloadEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 145 |
void getIpPayloadEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 146 |
void getTemiEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 147 |
void getScramblingStatusEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 148 |
void getIpCidChangeEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 149 |
void getRestartEvent(jobjectArray& arr, const int size, const DemuxFilterEvent& event); |
| 150 |
}; |
| 151 |
|
| 152 |
struct JTuner; |
| 153 |
struct FrontendClientCallbackImpl : public FrontendClientCallback { |
| 154 |
FrontendClientCallbackImpl(JTuner*, jweak); |
| 155 |
~FrontendClientCallbackImpl(); |
| 156 |
virtual void onEvent(FrontendEventType frontendEventType); |
| 157 |
virtual void onScanMessage( |
| 158 |
FrontendScanMessageType type, const FrontendScanMessage& message); |
| 159 |
|
| 160 |
void executeOnScanMessage(JNIEnv *env, const jclass& clazz, const jobject& frontend, |
| 161 |
FrontendScanMessageType type, |
| 162 |
const FrontendScanMessage& message); |
| 163 |
void addCallbackListener(JTuner*, jweak obj); |
| 164 |
void removeCallbackListener(JTuner* jtuner); |
| 165 |
std::unordered_map<JTuner*, jweak> mListenersMap; |
| 166 |
std::mutex mMutex; |
| 167 |
}; |
| 168 |
|
| 169 |
struct JTuner : public RefBase { |
| 170 |
JTuner(JNIEnv *env, jobject thiz); |
| 171 |
int getTunerVersion(); |
| 172 |
jobject getAvSyncHwId(sp<FilterClient> filter); |
| 173 |
jobject getAvSyncTime(jint id); |
| 174 |
int connectCiCam(jint id); |
| 175 |
int linkCiCam(jint id); |
| 176 |
int disconnectCiCam(); |
| 177 |
int unlinkCiCam(jint id); |
| 178 |
jobject getFrontendIds(); |
| 179 |
jobject openFrontendByHandle(int feHandle); |
| 180 |
int shareFrontend(int feId); |
| 181 |
int unshareFrontend(); |
| 182 |
void registerFeCbListener(JTuner* jtuner); |
| 183 |
void unregisterFeCbListener(JTuner* jtuner); |
| 184 |
void updateFrontend(JTuner* jtuner); |
| 185 |
jint closeFrontendById(int id); |
| 186 |
jobject getFrontendInfo(int id); |
| 187 |
int tune(const FrontendSettings& settings); |
| 188 |
int stopTune(); |
| 189 |
int scan(const FrontendSettings& settings, FrontendScanType scanType); |
| 190 |
int stopScan(); |
| 191 |
int setLnb(sp<LnbClient> lnbClient); |
| 192 |
int setLna(bool enable); |
| 193 |
jobject openLnbByHandle(int handle); |
| 194 |
jobject openLnbByName(jstring name); |
| 195 |
jobject openFilter(DemuxFilterType type, int bufferSize); |
| 196 |
jobject openTimeFilter(); |
| 197 |
jobject openDescrambler(); |
| 198 |
jobject openDvr(DvrType type, jlong bufferSize); |
| 199 |
jobject getDemuxCaps(); |
| 200 |
jobject getFrontendStatus(jintArray types); |
| 201 |
Result openDemux(int handle); |
| 202 |
jint close(); |
| 203 |
jint closeFrontend(); |
| 204 |
jint closeDemux(); |
| 205 |
Result getFrontendHardwareInfo(string& info); |
| 206 |
jint setMaxNumberOfFrontends(int32_t frontendType, int32_t maxNumber); |
| 207 |
int32_t getMaxNumberOfFrontends(int32_t frontendType); |
| 208 |
jint removeOutputPid(int32_t pid); |
| 209 |
jobjectArray getFrontendStatusReadiness(jintArray types); |
| 210 |
|
| 211 |
jweak getObject(); |
| 212 |
|
| 213 |
protected: |
| 214 |
virtual ~JTuner(); |
| 215 |
|
| 216 |
private: |
| 217 |
jclass mClass; |
| 218 |
jweak mObject; |
| 219 |
static sp<TunerClient> mTunerClient; |
| 220 |
sp<FrontendClient> mFeClient; |
| 221 |
sp<FrontendClientCallbackImpl> mFeClientCb; |
| 222 |
int mFeId; |
| 223 |
int mSharedFeId; |
| 224 |
sp<LnbClient> mLnbClient; |
| 225 |
sp<DemuxClient> mDemuxClient; |
| 226 |
static jobject getAnalogFrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 227 |
static jobject getAtsc3FrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 228 |
static jobject getAtscFrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 229 |
static jobject getDvbcFrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 230 |
static jobject getDvbsFrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 231 |
static jobject getDvbtFrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 232 |
static jobject getIsdbs3FrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 233 |
static jobject getIsdbsFrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 234 |
static jobject getIsdbtFrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 235 |
static jobject getDtmbFrontendCaps(JNIEnv* env, FrontendCapabilities& caps); |
| 236 |
}; |
| 237 |
|
| 238 |
class C2DataIdInfo : public C2Param { |
| 239 |
public: |
| 240 |
C2DataIdInfo(uint32_t index, uint64_t value); |
| 241 |
private: |
| 242 |
typedef C2GlobalParam<C2Info, C2Int64Value, 0> StubInfo; |
| 243 |
StubInfo mInfo; |
| 244 |
static const size_t kParamSize = sizeof(StubInfo); |
| 245 |
}; |
| 246 |
|
| 247 |
} |
| 248 |
|
| 249 |
#endif |