shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 "TvTuner-JNI" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include "android_media_tv_Tuner.h" |
| 21 | #include "android_runtime/AndroidRuntime.h" |
| 22 | |
| 23 | #include <android/hardware/tv/tuner/1.0/ITuner.h> |
| 24 | #include <media/stagefright/foundation/ADebug.h> |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 25 | #include <nativehelper/JNIHelp.h> |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 26 | |
| 27 | #pragma GCC diagnostic ignored "-Wunused-function" |
| 28 | |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 29 | using ::android::hardware::Void; |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 30 | using ::android::hardware::hidl_vec; |
shubang | 030afb5 | 2019-11-27 16:09:02 -0800 | [diff] [blame] | 31 | using ::android::hardware::tv::tuner::V1_0::DataFormat; |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 32 | using ::android::hardware::tv::tuner::V1_0::DemuxFilterMainType; |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 33 | using ::android::hardware::tv::tuner::V1_0::DemuxFilterPesDataSettings; |
| 34 | using ::android::hardware::tv::tuner::V1_0::DemuxFilterSettings; |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 35 | using ::android::hardware::tv::tuner::V1_0::DemuxMmtpPid; |
shubang | 964e613 | 2019-11-26 15:05:22 -0800 | [diff] [blame] | 36 | using ::android::hardware::tv::tuner::V1_0::DemuxQueueNotifyBits; |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 37 | using ::android::hardware::tv::tuner::V1_0::DemuxTpid; |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 38 | using ::android::hardware::tv::tuner::V1_0::DemuxTsFilterSettings; |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 39 | using ::android::hardware::tv::tuner::V1_0::DemuxTsFilterType; |
shubang | 030afb5 | 2019-11-27 16:09:02 -0800 | [diff] [blame] | 40 | using ::android::hardware::tv::tuner::V1_0::DvrSettings; |
shubang | 74bfd48 | 2019-10-29 19:10:22 -0700 | [diff] [blame] | 41 | using ::android::hardware::tv::tuner::V1_0::FrontendAnalogSettings; |
| 42 | using ::android::hardware::tv::tuner::V1_0::FrontendAnalogSifStandard; |
| 43 | using ::android::hardware::tv::tuner::V1_0::FrontendAnalogType; |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 44 | using ::android::hardware::tv::tuner::V1_0::ITuner; |
shubang | 030afb5 | 2019-11-27 16:09:02 -0800 | [diff] [blame] | 45 | using ::android::hardware::tv::tuner::V1_0::PlaybackSettings; |
| 46 | using ::android::hardware::tv::tuner::V1_0::RecordSettings; |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 47 | using ::android::hardware::tv::tuner::V1_0::Result; |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 48 | |
| 49 | struct fields_t { |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 50 | jfieldID tunerContext; |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 51 | jfieldID filterContext; |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 52 | jfieldID descramblerContext; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 53 | jfieldID dvrContext; |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 54 | jmethodID frontendInitID; |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 55 | jmethodID filterInitID; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 56 | jmethodID dvrInitID; |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 57 | jmethodID onFrontendEventID; |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 58 | jmethodID onFilterStatusID; |
shubang | 760f031 | 2019-11-12 17:11:28 -0800 | [diff] [blame] | 59 | jmethodID lnbInitID; |
| 60 | jmethodID onLnbEventID; |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 61 | jmethodID descramblerInitID; |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | static fields_t gFields; |
| 65 | |
| 66 | namespace android { |
shubang | 760f031 | 2019-11-12 17:11:28 -0800 | [diff] [blame] | 67 | /////////////// LnbCallback /////////////////////// |
| 68 | LnbCallback::LnbCallback(jweak tunerObj, LnbId id) : mObject(tunerObj), mId(id) {} |
| 69 | |
| 70 | Return<void> LnbCallback::onEvent(LnbEventType lnbEventType) { |
| 71 | ALOGD("LnbCallback::onEvent, type=%d", lnbEventType); |
| 72 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 73 | env->CallVoidMethod( |
| 74 | mObject, |
| 75 | gFields.onLnbEventID, |
| 76 | (jint)lnbEventType); |
| 77 | return Void(); |
| 78 | } |
| 79 | Return<void> LnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& /*diseqcMessage*/) { |
| 80 | ALOGD("LnbCallback::onDiseqcMessage"); |
| 81 | return Void(); |
| 82 | } |
| 83 | |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 84 | /////////////// DvrCallback /////////////////////// |
| 85 | Return<void> DvrCallback::onRecordStatus(RecordStatus /*status*/) { |
| 86 | ALOGD("DvrCallback::onRecordStatus"); |
| 87 | return Void(); |
| 88 | } |
| 89 | |
| 90 | Return<void> DvrCallback::onPlaybackStatus(PlaybackStatus /*status*/) { |
| 91 | ALOGD("DvrCallback::onPlaybackStatus"); |
| 92 | return Void(); |
| 93 | } |
| 94 | |
| 95 | void DvrCallback::setDvr(const jobject dvr) { |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 96 | ALOGD("DvrCallback::setDvr"); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 97 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 98 | mDvr = env->NewWeakGlobalRef(dvr); |
| 99 | } |
| 100 | |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 101 | /////////////// Dvr /////////////////////// |
| 102 | |
Greg Kaiser | 4aaee38 | 2020-01-07 09:42:10 -0800 | [diff] [blame] | 103 | Dvr::Dvr(sp<IDvr> sp, jweak obj) : mDvrSp(sp), mDvrObj(obj), mDvrMQEventFlag(nullptr) {} |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 104 | |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 105 | Dvr::~Dvr() { |
| 106 | EventFlag::deleteEventFlag(&mDvrMQEventFlag); |
| 107 | } |
| 108 | |
| 109 | int Dvr::close() { |
| 110 | Result r = mDvrSp->close(); |
| 111 | if (r == Result::SUCCESS) { |
| 112 | EventFlag::deleteEventFlag(&mDvrMQEventFlag); |
| 113 | } |
| 114 | return (int)r; |
| 115 | } |
| 116 | |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 117 | sp<IDvr> Dvr::getIDvr() { |
| 118 | return mDvrSp; |
| 119 | } |
| 120 | |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 121 | DvrMQ& Dvr::getDvrMQ() { |
| 122 | return *mDvrMQ; |
| 123 | } |
| 124 | |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 125 | /////////////// FilterCallback /////////////////////// |
| 126 | //TODO: implement filter callback |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 127 | Return<void> FilterCallback::onFilterEvent(const DemuxFilterEvent& /*filterEvent*/) { |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 128 | ALOGD("FilterCallback::onFilterEvent"); |
| 129 | return Void(); |
| 130 | } |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 131 | |
| 132 | Return<void> FilterCallback::onFilterStatus(const DemuxFilterStatus status) { |
| 133 | ALOGD("FilterCallback::onFilterStatus"); |
| 134 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 135 | env->CallVoidMethod( |
| 136 | mFilter, |
| 137 | gFields.onFilterStatusID, |
| 138 | (jint)status); |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 139 | return Void(); |
| 140 | } |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 141 | |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 142 | void FilterCallback::setFilter(const jobject filter) { |
| 143 | ALOGD("FilterCallback::setFilter"); |
| 144 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 145 | mFilter = env->NewWeakGlobalRef(filter); |
| 146 | } |
| 147 | |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 148 | /////////////// Filter /////////////////////// |
| 149 | |
| 150 | Filter::Filter(sp<IFilter> sp, jweak obj) : mFilterSp(sp), mFilterObj(obj) {} |
| 151 | |
shubang | 964e613 | 2019-11-26 15:05:22 -0800 | [diff] [blame] | 152 | Filter::~Filter() { |
| 153 | EventFlag::deleteEventFlag(&mFilterMQEventFlag); |
| 154 | } |
| 155 | |
| 156 | int Filter::close() { |
| 157 | Result r = mFilterSp->close(); |
| 158 | if (r == Result::SUCCESS) { |
| 159 | EventFlag::deleteEventFlag(&mFilterMQEventFlag); |
| 160 | } |
| 161 | return (int)r; |
| 162 | } |
| 163 | |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 164 | sp<IFilter> Filter::getIFilter() { |
| 165 | return mFilterSp; |
| 166 | } |
| 167 | |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 168 | /////////////// FrontendCallback /////////////////////// |
| 169 | |
| 170 | FrontendCallback::FrontendCallback(jweak tunerObj, FrontendId id) : mObject(tunerObj), mId(id) {} |
| 171 | |
| 172 | Return<void> FrontendCallback::onEvent(FrontendEventType frontendEventType) { |
| 173 | ALOGD("FrontendCallback::onEvent, type=%d", frontendEventType); |
| 174 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 175 | env->CallVoidMethod( |
| 176 | mObject, |
| 177 | gFields.onFrontendEventID, |
| 178 | (jint)frontendEventType); |
| 179 | return Void(); |
| 180 | } |
| 181 | Return<void> FrontendCallback::onDiseqcMessage(const hidl_vec<uint8_t>& /*diseqcMessage*/) { |
| 182 | ALOGD("FrontendCallback::onDiseqcMessage"); |
| 183 | return Void(); |
| 184 | } |
| 185 | |
| 186 | Return<void> FrontendCallback::onScanMessage( |
| 187 | FrontendScanMessageType type, const FrontendScanMessage& /*message*/) { |
| 188 | ALOGD("FrontendCallback::onScanMessage, type=%d", type); |
| 189 | return Void(); |
| 190 | } |
| 191 | |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 192 | /////////////// Tuner /////////////////////// |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 193 | |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 194 | sp<ITuner> JTuner::mTuner; |
| 195 | |
| 196 | JTuner::JTuner(JNIEnv *env, jobject thiz) |
| 197 | : mClass(NULL) { |
| 198 | jclass clazz = env->GetObjectClass(thiz); |
| 199 | CHECK(clazz != NULL); |
| 200 | |
| 201 | mClass = (jclass)env->NewGlobalRef(clazz); |
| 202 | mObject = env->NewWeakGlobalRef(thiz); |
| 203 | if (mTuner == NULL) { |
| 204 | mTuner = getTunerService(); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | JTuner::~JTuner() { |
| 209 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 210 | |
| 211 | env->DeleteGlobalRef(mClass); |
| 212 | mTuner = NULL; |
| 213 | mClass = NULL; |
| 214 | mObject = NULL; |
| 215 | } |
| 216 | |
| 217 | sp<ITuner> JTuner::getTunerService() { |
| 218 | if (mTuner == nullptr) { |
| 219 | mTuner = ITuner::getService(); |
| 220 | |
| 221 | if (mTuner == nullptr) { |
| 222 | ALOGW("Failed to get tuner service."); |
| 223 | } |
| 224 | } |
| 225 | return mTuner; |
| 226 | } |
| 227 | |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 228 | jobject JTuner::getFrontendIds() { |
| 229 | ALOGD("JTuner::getFrontendIds()"); |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 230 | mTuner->getFrontendIds([&](Result, const hidl_vec<FrontendId>& frontendIds) { |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 231 | mFeIds = frontendIds; |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 232 | }); |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 233 | if (mFeIds.size() == 0) { |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 234 | ALOGW("Frontend isn't available"); |
| 235 | return NULL; |
| 236 | } |
| 237 | |
| 238 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 239 | jclass arrayListClazz = env->FindClass("java/util/ArrayList"); |
| 240 | jmethodID arrayListAdd = env->GetMethodID(arrayListClazz, "add", "(Ljava/lang/Object;)Z"); |
| 241 | jobject obj = env->NewObject(arrayListClazz, env->GetMethodID(arrayListClazz, "<init>", "()V")); |
| 242 | |
| 243 | jclass integerClazz = env->FindClass("java/lang/Integer"); |
| 244 | jmethodID intInit = env->GetMethodID(integerClazz, "<init>", "(I)V"); |
| 245 | |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 246 | for (int i=0; i < mFeIds.size(); i++) { |
| 247 | jobject idObj = env->NewObject(integerClazz, intInit, mFeIds[i]); |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 248 | env->CallBooleanMethod(obj, arrayListAdd, idObj); |
| 249 | } |
| 250 | return obj; |
| 251 | } |
| 252 | |
| 253 | jobject JTuner::openFrontendById(int id) { |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 254 | sp<IFrontend> fe; |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 255 | mTuner->openFrontendById(id, [&](Result, const sp<IFrontend>& frontend) { |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 256 | fe = frontend; |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 257 | }); |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 258 | if (fe == nullptr) { |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 259 | ALOGE("Failed to open frontend"); |
| 260 | return NULL; |
| 261 | } |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 262 | mFe = fe; |
| 263 | sp<FrontendCallback> feCb = new FrontendCallback(mObject, id); |
| 264 | fe->setCallback(feCb); |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 265 | |
| 266 | jint jId = (jint) id; |
shubang | 964e613 | 2019-11-26 15:05:22 -0800 | [diff] [blame] | 267 | |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 268 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 269 | // TODO: add more fields to frontend |
| 270 | return env->NewObject( |
| 271 | env->FindClass("android/media/tv/tuner/Tuner$Frontend"), |
| 272 | gFields.frontendInitID, |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 273 | mObject, |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 274 | (jint) jId); |
| 275 | } |
| 276 | |
shubang | 760f031 | 2019-11-12 17:11:28 -0800 | [diff] [blame] | 277 | jobject JTuner::getLnbIds() { |
| 278 | ALOGD("JTuner::getLnbIds()"); |
| 279 | mTuner->getLnbIds([&](Result, const hidl_vec<FrontendId>& lnbIds) { |
| 280 | mLnbIds = lnbIds; |
| 281 | }); |
| 282 | if (mLnbIds.size() == 0) { |
| 283 | ALOGW("Lnb isn't available"); |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 288 | jclass arrayListClazz = env->FindClass("java/util/ArrayList"); |
| 289 | jmethodID arrayListAdd = env->GetMethodID(arrayListClazz, "add", "(Ljava/lang/Object;)Z"); |
| 290 | jobject obj = env->NewObject(arrayListClazz, env->GetMethodID(arrayListClazz, "<init>", "()V")); |
| 291 | |
| 292 | jclass integerClazz = env->FindClass("java/lang/Integer"); |
| 293 | jmethodID intInit = env->GetMethodID(integerClazz, "<init>", "(I)V"); |
| 294 | |
| 295 | for (int i=0; i < mLnbIds.size(); i++) { |
| 296 | jobject idObj = env->NewObject(integerClazz, intInit, mLnbIds[i]); |
| 297 | env->CallBooleanMethod(obj, arrayListAdd, idObj); |
| 298 | } |
| 299 | return obj; |
| 300 | } |
| 301 | |
| 302 | jobject JTuner::openLnbById(int id) { |
| 303 | sp<ILnb> lnbSp; |
| 304 | mTuner->openLnbById(id, [&](Result, const sp<ILnb>& lnb) { |
| 305 | lnbSp = lnb; |
| 306 | }); |
| 307 | if (lnbSp == nullptr) { |
| 308 | ALOGE("Failed to open lnb"); |
| 309 | return NULL; |
| 310 | } |
| 311 | mLnb = lnbSp; |
| 312 | sp<LnbCallback> lnbCb = new LnbCallback(mObject, id); |
| 313 | mLnb->setCallback(lnbCb); |
| 314 | |
| 315 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 316 | return env->NewObject( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 317 | env->FindClass("android/media/tv/tuner/Lnb"), |
shubang | 760f031 | 2019-11-12 17:11:28 -0800 | [diff] [blame] | 318 | gFields.lnbInitID, |
| 319 | mObject, |
| 320 | id); |
| 321 | } |
| 322 | |
shubang | 74bfd48 | 2019-10-29 19:10:22 -0700 | [diff] [blame] | 323 | int JTuner::tune(const FrontendSettings& settings) { |
| 324 | if (mFe == NULL) { |
| 325 | ALOGE("frontend is not initialized"); |
| 326 | return (int)Result::INVALID_STATE; |
| 327 | } |
| 328 | Result result = mFe->tune(settings); |
| 329 | return (int)result; |
| 330 | } |
| 331 | |
shubang | d5b845f | 2019-12-11 15:29:09 -0800 | [diff] [blame] | 332 | int JTuner::scan(const FrontendSettings& settings, FrontendScanType scanType) { |
| 333 | if (mFe == NULL) { |
| 334 | ALOGE("frontend is not initialized"); |
| 335 | return (int)Result::INVALID_STATE; |
| 336 | } |
| 337 | Result result = mFe->scan(settings, scanType); |
| 338 | return (int)result; |
| 339 | } |
| 340 | |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 341 | bool JTuner::openDemux() { |
| 342 | if (mTuner == nullptr) { |
| 343 | return false; |
| 344 | } |
| 345 | if (mDemux != nullptr) { |
| 346 | return true; |
| 347 | } |
| 348 | mTuner->openDemux([&](Result, uint32_t demuxId, const sp<IDemux>& demux) { |
| 349 | mDemux = demux; |
| 350 | mDemuxId = demuxId; |
| 351 | ALOGD("open demux, id = %d", demuxId); |
| 352 | }); |
| 353 | if (mDemux == nullptr) { |
| 354 | return false; |
| 355 | } |
| 356 | return true; |
| 357 | } |
| 358 | |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 359 | jobject JTuner::openDescrambler() { |
| 360 | ALOGD("JTuner::openDescrambler"); |
| 361 | if (mTuner == nullptr) { |
| 362 | return NULL; |
| 363 | } |
| 364 | sp<IDescrambler> descramblerSp; |
| 365 | mTuner->openDescrambler([&](Result, const sp<IDescrambler>& descrambler) { |
| 366 | descramblerSp = descrambler; |
| 367 | }); |
| 368 | |
| 369 | if (descramblerSp == NULL) { |
| 370 | return NULL; |
| 371 | } |
| 372 | |
| 373 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 374 | jobject descramblerObj = |
| 375 | env->NewObject( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 376 | env->FindClass("android/media/tv/tuner/Descrambler"), |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 377 | gFields.descramblerInitID, |
| 378 | mObject); |
| 379 | |
| 380 | descramblerSp->incStrong(descramblerObj); |
| 381 | env->SetLongField(descramblerObj, gFields.descramblerContext, (jlong)descramblerSp.get()); |
| 382 | |
| 383 | return descramblerObj; |
| 384 | } |
| 385 | |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 386 | jobject JTuner::openFilter(DemuxFilterType type, int bufferSize) { |
| 387 | if (mDemux == NULL) { |
| 388 | if (!openDemux()) { |
| 389 | return NULL; |
| 390 | } |
| 391 | } |
| 392 | |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 393 | sp<IFilter> iFilterSp; |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 394 | sp<FilterCallback> callback = new FilterCallback(); |
| 395 | mDemux->openFilter(type, bufferSize, callback, |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 396 | [&](Result, const sp<IFilter>& filter) { |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 397 | iFilterSp = filter; |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 398 | }); |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 399 | if (iFilterSp == NULL) { |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 400 | ALOGD("Failed to open filter, type = %d", type.mainType); |
| 401 | return NULL; |
| 402 | } |
| 403 | int fId; |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 404 | iFilterSp->getId([&](Result, uint32_t filterId) { |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 405 | fId = filterId; |
| 406 | }); |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 407 | |
| 408 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 409 | jobject filterObj = |
| 410 | env->NewObject( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 411 | env->FindClass("android/media/tv/tuner/filter/Filter"), |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 412 | gFields.filterInitID, |
| 413 | mObject, |
| 414 | (jint) fId); |
| 415 | |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 416 | sp<Filter> filterSp = new Filter(iFilterSp, filterObj); |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 417 | filterSp->incStrong(filterObj); |
| 418 | env->SetLongField(filterObj, gFields.filterContext, (jlong)filterSp.get()); |
| 419 | |
| 420 | callback->setFilter(filterObj); |
| 421 | |
| 422 | return filterObj; |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 423 | } |
| 424 | |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 425 | jobject JTuner::openDvr(DvrType type, int bufferSize) { |
| 426 | ALOGD("JTuner::openDvr"); |
| 427 | if (mDemux == NULL) { |
| 428 | if (!openDemux()) { |
| 429 | return NULL; |
| 430 | } |
| 431 | } |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 432 | sp<IDvr> iDvrSp; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 433 | sp<DvrCallback> callback = new DvrCallback(); |
| 434 | mDemux->openDvr(type, bufferSize, callback, |
| 435 | [&](Result, const sp<IDvr>& dvr) { |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 436 | iDvrSp = dvr; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 437 | }); |
| 438 | |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 439 | if (iDvrSp == NULL) { |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 440 | return NULL; |
| 441 | } |
| 442 | |
| 443 | JNIEnv *env = AndroidRuntime::getJNIEnv(); |
| 444 | jobject dvrObj = |
| 445 | env->NewObject( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 446 | env->FindClass("android/media/tv/tuner/dvr/Dvr"), |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 447 | gFields.dvrInitID, |
| 448 | mObject); |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 449 | sp<Dvr> dvrSp = new Dvr(iDvrSp, dvrObj); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 450 | dvrSp->incStrong(dvrObj); |
| 451 | env->SetLongField(dvrObj, gFields.dvrContext, (jlong)dvrSp.get()); |
| 452 | |
| 453 | callback->setDvr(dvrObj); |
| 454 | |
| 455 | return dvrObj; |
| 456 | } |
| 457 | |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 458 | } // namespace android |
| 459 | |
| 460 | //////////////////////////////////////////////////////////////////////////////// |
| 461 | |
| 462 | using namespace android; |
| 463 | |
| 464 | static sp<JTuner> setTuner(JNIEnv *env, jobject thiz, const sp<JTuner> &tuner) { |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 465 | sp<JTuner> old = (JTuner *)env->GetLongField(thiz, gFields.tunerContext); |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 466 | |
| 467 | if (tuner != NULL) { |
| 468 | tuner->incStrong(thiz); |
| 469 | } |
| 470 | if (old != NULL) { |
| 471 | old->decStrong(thiz); |
| 472 | } |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 473 | env->SetLongField(thiz, gFields.tunerContext, (jlong)tuner.get()); |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 474 | |
| 475 | return old; |
| 476 | } |
| 477 | |
| 478 | static sp<JTuner> getTuner(JNIEnv *env, jobject thiz) { |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 479 | return (JTuner *)env->GetLongField(thiz, gFields.tunerContext); |
| 480 | } |
| 481 | |
| 482 | static sp<IDescrambler> getDescrambler(JNIEnv *env, jobject descrambler) { |
| 483 | return (IDescrambler *)env->GetLongField(descrambler, gFields.descramblerContext); |
| 484 | } |
| 485 | |
| 486 | static DemuxPid getDemuxPid(int pidType, int pid) { |
| 487 | DemuxPid demuxPid; |
| 488 | if ((int)pidType == 1) { |
| 489 | demuxPid.tPid(static_cast<DemuxTpid>(pid)); |
| 490 | } else if ((int)pidType == 2) { |
| 491 | demuxPid.mmtpPid(static_cast<DemuxMmtpPid>(pid)); |
| 492 | } |
| 493 | return demuxPid; |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 494 | } |
| 495 | |
shubang | 74bfd48 | 2019-10-29 19:10:22 -0700 | [diff] [blame] | 496 | static FrontendSettings getFrontendSettings(JNIEnv *env, int type, jobject settings) { |
| 497 | FrontendSettings frontendSettings; |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 498 | jclass clazz = env->FindClass("android/media/tv/tuner/frontend/FrontendSettings"); |
shubang | 964e613 | 2019-11-26 15:05:22 -0800 | [diff] [blame] | 499 | jfieldID freqField = env->GetFieldID(clazz, "mFrequency", "I"); |
shubang | 74bfd48 | 2019-10-29 19:10:22 -0700 | [diff] [blame] | 500 | uint32_t freq = static_cast<uint32_t>(env->GetIntField(clazz, freqField)); |
| 501 | |
| 502 | // TODO: handle the other 8 types of settings |
| 503 | if (type == 1) { |
| 504 | // analog |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 505 | clazz = env->FindClass("android/media/tv/tuner/frontend/AnalogFrontendSettings"); |
shubang | 74bfd48 | 2019-10-29 19:10:22 -0700 | [diff] [blame] | 506 | FrontendAnalogType analogType = |
| 507 | static_cast<FrontendAnalogType>( |
| 508 | env->GetIntField(settings, env->GetFieldID(clazz, "mAnalogType", "I"))); |
| 509 | FrontendAnalogSifStandard sifStandard = |
| 510 | static_cast<FrontendAnalogSifStandard>( |
| 511 | env->GetIntField(settings, env->GetFieldID(clazz, "mSifStandard", "I"))); |
| 512 | FrontendAnalogSettings frontendAnalogSettings { |
| 513 | .frequency = freq, |
| 514 | .type = analogType, |
| 515 | .sifStandard = sifStandard, |
| 516 | }; |
| 517 | frontendSettings.analog(frontendAnalogSettings); |
| 518 | } |
| 519 | return frontendSettings; |
| 520 | } |
| 521 | |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 522 | static sp<Filter> getFilter(JNIEnv *env, jobject filter) { |
| 523 | return (Filter *)env->GetLongField(filter, gFields.filterContext); |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 524 | } |
| 525 | |
shubang | 030afb5 | 2019-11-27 16:09:02 -0800 | [diff] [blame] | 526 | static DvrSettings getDvrSettings(JNIEnv *env, jobject settings) { |
| 527 | DvrSettings dvrSettings; |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 528 | jclass clazz = env->FindClass("android/media/tv/tuner/dvr/DvrSettings"); |
shubang | 030afb5 | 2019-11-27 16:09:02 -0800 | [diff] [blame] | 529 | uint32_t statusMask = |
| 530 | static_cast<uint32_t>(env->GetIntField( |
| 531 | settings, env->GetFieldID(clazz, "mStatusMask", "I"))); |
| 532 | uint32_t lowThreshold = |
| 533 | static_cast<uint32_t>(env->GetIntField( |
| 534 | settings, env->GetFieldID(clazz, "mLowThreshold", "I"))); |
| 535 | uint32_t highThreshold = |
| 536 | static_cast<uint32_t>(env->GetIntField( |
| 537 | settings, env->GetFieldID(clazz, "mHighThreshold", "I"))); |
| 538 | uint8_t packetSize = |
| 539 | static_cast<uint8_t>(env->GetIntField( |
| 540 | settings, env->GetFieldID(clazz, "mPacketSize", "I"))); |
| 541 | DataFormat dataFormat = |
| 542 | static_cast<DataFormat>(env->GetIntField( |
| 543 | settings, env->GetFieldID(clazz, "mDataFormat", "I"))); |
| 544 | DvrType type = |
| 545 | static_cast<DvrType>(env->GetIntField( |
| 546 | settings, env->GetFieldID(clazz, "mType", "I"))); |
| 547 | if (type == DvrType::RECORD) { |
| 548 | RecordSettings recordSettings { |
| 549 | .statusMask = static_cast<unsigned char>(statusMask), |
| 550 | .lowThreshold = lowThreshold, |
| 551 | .highThreshold = highThreshold, |
| 552 | .dataFormat = dataFormat, |
| 553 | .packetSize = packetSize, |
| 554 | }; |
| 555 | dvrSettings.record(recordSettings); |
| 556 | } else if (type == DvrType::PLAYBACK) { |
| 557 | PlaybackSettings PlaybackSettings { |
| 558 | .statusMask = statusMask, |
| 559 | .lowThreshold = lowThreshold, |
| 560 | .highThreshold = highThreshold, |
| 561 | .dataFormat = dataFormat, |
| 562 | .packetSize = packetSize, |
| 563 | }; |
| 564 | dvrSettings.playback(PlaybackSettings); |
| 565 | } |
| 566 | return dvrSettings; |
| 567 | } |
| 568 | |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 569 | static sp<Dvr> getDvr(JNIEnv *env, jobject dvr) { |
| 570 | return (Dvr *)env->GetLongField(dvr, gFields.dvrContext); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 571 | } |
| 572 | |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 573 | static void android_media_tv_Tuner_native_init(JNIEnv *env) { |
| 574 | jclass clazz = env->FindClass("android/media/tv/tuner/Tuner"); |
| 575 | CHECK(clazz != NULL); |
| 576 | |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 577 | gFields.tunerContext = env->GetFieldID(clazz, "mNativeContext", "J"); |
| 578 | CHECK(gFields.tunerContext != NULL); |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 579 | |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 580 | gFields.onFrontendEventID = env->GetMethodID(clazz, "onFrontendEvent", "(I)V"); |
| 581 | |
shubang | 760f031 | 2019-11-12 17:11:28 -0800 | [diff] [blame] | 582 | gFields.onLnbEventID = env->GetMethodID(clazz, "onLnbEvent", "(I)V"); |
| 583 | |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 584 | jclass frontendClazz = env->FindClass("android/media/tv/tuner/Tuner$Frontend"); |
shubang | 4b8c540 | 2019-10-24 17:49:53 -0700 | [diff] [blame] | 585 | gFields.frontendInitID = |
| 586 | env->GetMethodID(frontendClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;I)V"); |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 587 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 588 | jclass lnbClazz = env->FindClass("android/media/tv/tuner/Lnb"); |
shubang | 760f031 | 2019-11-12 17:11:28 -0800 | [diff] [blame] | 589 | gFields.lnbInitID = |
| 590 | env->GetMethodID(lnbClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;I)V"); |
| 591 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 592 | jclass filterClazz = env->FindClass("android/media/tv/tuner/filter/Filter"); |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 593 | gFields.filterContext = env->GetFieldID(filterClazz, "mNativeContext", "J"); |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 594 | gFields.filterInitID = |
| 595 | env->GetMethodID(filterClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;I)V"); |
shubang | cdf30de | 2019-11-06 17:28:38 -0800 | [diff] [blame] | 596 | gFields.onFilterStatusID = |
| 597 | env->GetMethodID(filterClazz, "onFilterStatus", "(I)V"); |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 598 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 599 | jclass descramblerClazz = env->FindClass("android/media/tv/tuner/Descrambler"); |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 600 | gFields.descramblerContext = env->GetFieldID(descramblerClazz, "mNativeContext", "J"); |
| 601 | gFields.descramblerInitID = |
| 602 | env->GetMethodID(descramblerClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;)V"); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 603 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 604 | jclass dvrClazz = env->FindClass("android/media/tv/tuner/dvr/Dvr"); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 605 | gFields.dvrContext = env->GetFieldID(dvrClazz, "mNativeContext", "J"); |
| 606 | gFields.dvrInitID = env->GetMethodID(dvrClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;)V"); |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static void android_media_tv_Tuner_native_setup(JNIEnv *env, jobject thiz) { |
| 610 | sp<JTuner> tuner = new JTuner(env, thiz); |
| 611 | setTuner(env,thiz, tuner); |
| 612 | } |
| 613 | |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 614 | static jobject android_media_tv_Tuner_get_frontend_ids(JNIEnv *env, jobject thiz) { |
| 615 | sp<JTuner> tuner = getTuner(env, thiz); |
| 616 | return tuner->getFrontendIds(); |
| 617 | } |
| 618 | |
| 619 | static jobject android_media_tv_Tuner_open_frontend_by_id(JNIEnv *env, jobject thiz, jint id) { |
| 620 | sp<JTuner> tuner = getTuner(env, thiz); |
| 621 | return tuner->openFrontendById(id); |
| 622 | } |
| 623 | |
shubang | 74bfd48 | 2019-10-29 19:10:22 -0700 | [diff] [blame] | 624 | static int android_media_tv_Tuner_tune(JNIEnv *env, jobject thiz, jint type, jobject settings) { |
| 625 | sp<JTuner> tuner = getTuner(env, thiz); |
| 626 | return tuner->tune(getFrontendSettings(env, type, settings)); |
| 627 | } |
| 628 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 629 | static int android_media_tv_Tuner_stop_tune(JNIEnv*, jobject) { |
shubang | e65b686 | 2019-12-17 15:43:35 -0800 | [diff] [blame] | 630 | return 0; |
| 631 | } |
| 632 | |
shubang | d5b845f | 2019-12-11 15:29:09 -0800 | [diff] [blame] | 633 | static int android_media_tv_Tuner_scan( |
| 634 | JNIEnv *env, jobject thiz, jint settingsType, jobject settings, jint scanType) { |
| 635 | sp<JTuner> tuner = getTuner(env, thiz); |
| 636 | return tuner->scan(getFrontendSettings( |
| 637 | env, settingsType, settings), static_cast<FrontendScanType>(scanType)); |
| 638 | } |
| 639 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 640 | static int android_media_tv_Tuner_stop_scan(JNIEnv*, jobject) { |
shubang | e65b686 | 2019-12-17 15:43:35 -0800 | [diff] [blame] | 641 | return 0; |
| 642 | } |
| 643 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 644 | static int android_media_tv_Tuner_set_lnb(JNIEnv*, jobject, jint) { |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | static int android_media_tv_Tuner_set_lna(JNIEnv*, jobject, jint, jboolean) { |
shubang | e65b686 | 2019-12-17 15:43:35 -0800 | [diff] [blame] | 649 | return 0; |
| 650 | } |
| 651 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 652 | static jobject android_media_tv_Tuner_get_frontend_status(JNIEnv, jobject, jintArray) { |
shubang | 1512ec1 | 2019-12-23 18:22:42 -0800 | [diff] [blame] | 653 | return NULL; |
| 654 | } |
| 655 | |
shubang | 7343fee | 2019-12-27 12:02:08 -0800 | [diff] [blame] | 656 | static int android_media_tv_Tuner_gat_av_sync_hw_id(JNIEnv*, jobject, jobject) { |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | static jlong android_media_tv_Tuner_gat_av_sync_time(JNIEnv*, jobject, jint) { |
| 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | static int android_media_tv_Tuner_connect_cicam(JNIEnv*, jobject, jint) { |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | static int android_media_tv_Tuner_disconnect_cicam(JNIEnv*, jobject) { |
| 669 | return 0; |
| 670 | } |
| 671 | |
shubang | 95c1f75 | 2019-12-27 16:29:48 -0800 | [diff] [blame] | 672 | static jobject android_media_tv_Tuner_get_frontend_info(JNIEnv*, jobject, jint) { |
| 673 | return NULL; |
| 674 | } |
| 675 | |
shubang | 760f031 | 2019-11-12 17:11:28 -0800 | [diff] [blame] | 676 | static jobject android_media_tv_Tuner_get_lnb_ids(JNIEnv *env, jobject thiz) { |
| 677 | sp<JTuner> tuner = getTuner(env, thiz); |
| 678 | return tuner->getLnbIds(); |
| 679 | } |
| 680 | |
| 681 | static jobject android_media_tv_Tuner_open_lnb_by_id(JNIEnv *env, jobject thiz, jint id) { |
| 682 | sp<JTuner> tuner = getTuner(env, thiz); |
| 683 | return tuner->openLnbById(id); |
| 684 | } |
| 685 | |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 686 | static jobject android_media_tv_Tuner_open_filter( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 687 | JNIEnv *env, jobject thiz, jint type, jint subType, jlong bufferSize) { |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 688 | sp<JTuner> tuner = getTuner(env, thiz); |
| 689 | DemuxFilterType filterType { |
| 690 | .mainType = static_cast<DemuxFilterMainType>(type), |
| 691 | }; |
| 692 | |
| 693 | // TODO: other sub types |
| 694 | filterType.subType.tsFilterType(static_cast<DemuxTsFilterType>(subType)); |
| 695 | |
| 696 | return tuner->openFilter(filterType, bufferSize); |
| 697 | } |
| 698 | |
shubang | 4347e2e | 2019-12-13 17:20:40 -0800 | [diff] [blame] | 699 | static jobject android_media_tv_Tuner_open_time_filter(JNIEnv, jobject) { |
| 700 | return NULL; |
| 701 | } |
| 702 | |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 703 | static DemuxFilterSettings getFilterSettings( |
| 704 | JNIEnv *env, int type, int subtype, jobject filterSettingsObj) { |
| 705 | DemuxFilterSettings filterSettings; |
| 706 | // TODO: more setting types |
| 707 | jobject settingsObj = |
| 708 | env->GetObjectField( |
| 709 | filterSettingsObj, |
| 710 | env->GetFieldID( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 711 | env->FindClass("android/media/tv/tuner/filter/FilterConfiguration"), |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 712 | "mSettings", |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 713 | "Landroid/media/tv/tuner/filter/Settings;")); |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 714 | if (type == (int)DemuxFilterMainType::TS) { |
| 715 | // DemuxTsFilterSettings |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 716 | jclass clazz = env->FindClass("android/media/tv/tuner/filter/TsFilterConfiguration"); |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 717 | int tpid = env->GetIntField(filterSettingsObj, env->GetFieldID(clazz, "mTpid", "I")); |
| 718 | if (subtype == (int)DemuxTsFilterType::PES) { |
| 719 | // DemuxFilterPesDataSettings |
| 720 | jclass settingClazz = |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 721 | env->FindClass("android/media/tv/tuner/filter/PesSettings"); |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 722 | int streamId = env->GetIntField( |
| 723 | settingsObj, env->GetFieldID(settingClazz, "mStreamId", "I")); |
| 724 | bool isRaw = (bool)env->GetBooleanField( |
| 725 | settingsObj, env->GetFieldID(settingClazz, "mIsRaw", "Z")); |
| 726 | DemuxFilterPesDataSettings filterPesDataSettings { |
| 727 | .streamId = static_cast<uint16_t>(streamId), |
| 728 | .isRaw = isRaw, |
| 729 | }; |
| 730 | DemuxTsFilterSettings tsFilterSettings { |
| 731 | .tpid = static_cast<uint16_t>(tpid), |
| 732 | }; |
| 733 | tsFilterSettings.filterSettings.pesData(filterPesDataSettings); |
| 734 | filterSettings.ts(tsFilterSettings); |
| 735 | } |
| 736 | } |
| 737 | return filterSettings; |
| 738 | } |
| 739 | |
shubang | 964e613 | 2019-11-26 15:05:22 -0800 | [diff] [blame] | 740 | static int copyData(JNIEnv *env, sp<Filter> filter, jbyteArray buffer, jint offset, int size) { |
| 741 | ALOGD("copyData, size=%d, offset=%d", size, offset); |
| 742 | |
| 743 | int available = filter->mFilterMQ->availableToRead(); |
| 744 | ALOGD("copyData, available=%d", available); |
| 745 | size = std::min(size, available); |
| 746 | |
| 747 | jboolean isCopy; |
| 748 | jbyte *dst = env->GetByteArrayElements(buffer, &isCopy); |
| 749 | ALOGD("copyData, isCopy=%d", isCopy); |
| 750 | if (dst == nullptr) { |
| 751 | ALOGD("Failed to GetByteArrayElements"); |
| 752 | return 0; |
| 753 | } |
| 754 | |
| 755 | if (filter->mFilterMQ->read(reinterpret_cast<unsigned char*>(dst) + offset, size)) { |
| 756 | env->ReleaseByteArrayElements(buffer, dst, 0); |
| 757 | filter->mFilterMQEventFlag->wake(static_cast<uint32_t>(DemuxQueueNotifyBits::DATA_CONSUMED)); |
| 758 | } else { |
| 759 | ALOGD("Failed to read FMQ"); |
| 760 | env->ReleaseByteArrayElements(buffer, dst, 0); |
| 761 | return 0; |
| 762 | } |
| 763 | return size; |
| 764 | } |
| 765 | |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 766 | static int android_media_tv_Tuner_configure_filter( |
| 767 | JNIEnv *env, jobject filter, int type, int subtype, jobject settings) { |
| 768 | ALOGD("configure filter type=%d, subtype=%d", type, subtype); |
shubang | 964e613 | 2019-11-26 15:05:22 -0800 | [diff] [blame] | 769 | sp<Filter> filterSp = getFilter(env, filter); |
| 770 | sp<IFilter> iFilterSp = filterSp->getIFilter(); |
| 771 | if (iFilterSp == NULL) { |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 772 | ALOGD("Failed to configure filter: filter not found"); |
| 773 | return (int)Result::INVALID_STATE; |
| 774 | } |
| 775 | DemuxFilterSettings filterSettings = getFilterSettings(env, type, subtype, settings); |
shubang | 964e613 | 2019-11-26 15:05:22 -0800 | [diff] [blame] | 776 | Result res = iFilterSp->configure(filterSettings); |
| 777 | MQDescriptorSync<uint8_t> filterMQDesc; |
| 778 | if (res == Result::SUCCESS && filterSp->mFilterMQ == NULL) { |
| 779 | Result getQueueDescResult = Result::UNKNOWN_ERROR; |
| 780 | iFilterSp->getQueueDesc( |
| 781 | [&](Result r, const MQDescriptorSync<uint8_t>& desc) { |
| 782 | filterMQDesc = desc; |
| 783 | getQueueDescResult = r; |
| 784 | ALOGD("getFilterQueueDesc"); |
| 785 | }); |
| 786 | if (getQueueDescResult == Result::SUCCESS) { |
| 787 | filterSp->mFilterMQ = std::make_unique<FilterMQ>(filterMQDesc, true); |
| 788 | EventFlag::createEventFlag( |
| 789 | filterSp->mFilterMQ->getEventFlagWord(), &(filterSp->mFilterMQEventFlag)); |
| 790 | } |
| 791 | } |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 792 | return (int)res; |
| 793 | } |
| 794 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 795 | static int android_media_tv_Tuner_get_filter_id(JNIEnv*, jobject) { |
| 796 | return 0; |
| 797 | } |
| 798 | |
| 799 | static int android_media_tv_Tuner_set_filter_data_source(JNIEnv*, jobject, jobject) { |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | static int android_media_tv_Tuner_start_filter(JNIEnv *env, jobject filter) { |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 804 | sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 805 | if (filterSp == NULL) { |
| 806 | ALOGD("Failed to start filter: filter not found"); |
| 807 | return false; |
| 808 | } |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 809 | Result r = filterSp->start(); |
| 810 | return (int) r; |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 811 | } |
| 812 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 813 | static int android_media_tv_Tuner_stop_filter(JNIEnv *env, jobject filter) { |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 814 | sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 815 | if (filterSp == NULL) { |
| 816 | ALOGD("Failed to stop filter: filter not found"); |
| 817 | return false; |
| 818 | } |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 819 | Result r = filterSp->stop(); |
| 820 | return (int) r; |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 821 | } |
| 822 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 823 | static int android_media_tv_Tuner_flush_filter(JNIEnv *env, jobject filter) { |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 824 | sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 825 | if (filterSp == NULL) { |
| 826 | ALOGD("Failed to flush filter: filter not found"); |
| 827 | return false; |
| 828 | } |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 829 | Result r = filterSp->flush(); |
| 830 | return (int) r; |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 831 | } |
| 832 | |
shubang | 964e613 | 2019-11-26 15:05:22 -0800 | [diff] [blame] | 833 | static int android_media_tv_Tuner_read_filter_fmq( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 834 | JNIEnv *env, jobject filter, jbyteArray buffer, jlong offset, jlong size) { |
shubang | 964e613 | 2019-11-26 15:05:22 -0800 | [diff] [blame] | 835 | sp<Filter> filterSp = getFilter(env, filter); |
| 836 | if (filterSp == NULL) { |
| 837 | ALOGD("Failed to read filter FMQ: filter not found"); |
| 838 | return 0; |
| 839 | } |
| 840 | return copyData(env, filterSp, buffer, offset, size); |
| 841 | } |
| 842 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 843 | static int android_media_tv_Tuner_close_filter(JNIEnv*, jobject) { |
| 844 | return 0; |
| 845 | } |
| 846 | |
shubang | 4347e2e | 2019-12-13 17:20:40 -0800 | [diff] [blame] | 847 | // TODO: implement TimeFilter functions |
| 848 | static int android_media_tv_Tuner_time_filter_set_timestamp( |
| 849 | JNIEnv, jobject, jlong) { |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | static int android_media_tv_Tuner_time_filter_clear_timestamp(JNIEnv, jobject) { |
| 854 | return 0; |
| 855 | } |
| 856 | |
| 857 | static jobject android_media_tv_Tuner_time_filter_get_timestamp(JNIEnv, jobject) { |
| 858 | return NULL; |
| 859 | } |
| 860 | |
| 861 | static jobject android_media_tv_Tuner_time_filter_get_source_time(JNIEnv, jobject) { |
| 862 | return NULL; |
| 863 | } |
| 864 | |
| 865 | static int android_media_tv_Tuner_time_filter_close(JNIEnv, jobject) { |
| 866 | return 0; |
| 867 | } |
| 868 | |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 869 | static jobject android_media_tv_Tuner_open_descrambler(JNIEnv *env, jobject thiz) { |
| 870 | sp<JTuner> tuner = getTuner(env, thiz); |
| 871 | return tuner->openDescrambler(); |
| 872 | } |
| 873 | |
shubang | 99c8992 | 2019-12-17 17:33:15 -0800 | [diff] [blame] | 874 | static int android_media_tv_Tuner_add_pid( |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 875 | JNIEnv *env, jobject descrambler, jint pidType, jint pid, jobject filter) { |
| 876 | sp<IDescrambler> descramblerSp = getDescrambler(env, descrambler); |
| 877 | if (descramblerSp == NULL) { |
| 878 | return false; |
| 879 | } |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 880 | sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 881 | Result result = descramblerSp->addPid(getDemuxPid((int)pidType, (int)pid), filterSp); |
shubang | 99c8992 | 2019-12-17 17:33:15 -0800 | [diff] [blame] | 882 | return (int)result; |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 883 | } |
| 884 | |
shubang | 99c8992 | 2019-12-17 17:33:15 -0800 | [diff] [blame] | 885 | static int android_media_tv_Tuner_remove_pid( |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 886 | JNIEnv *env, jobject descrambler, jint pidType, jint pid, jobject filter) { |
| 887 | sp<IDescrambler> descramblerSp = getDescrambler(env, descrambler); |
| 888 | if (descramblerSp == NULL) { |
| 889 | return false; |
| 890 | } |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 891 | sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 892 | Result result = descramblerSp->removePid(getDemuxPid((int)pidType, (int)pid), filterSp); |
shubang | 99c8992 | 2019-12-17 17:33:15 -0800 | [diff] [blame] | 893 | return (int)result; |
| 894 | } |
| 895 | |
| 896 | static int android_media_tv_Tuner_set_key_token(JNIEnv, jobject, jbyteArray) { |
| 897 | return 0; |
| 898 | } |
| 899 | |
| 900 | static int android_media_tv_Tuner_close_descrambler(JNIEnv, jobject) { |
| 901 | return 0; |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 902 | } |
| 903 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 904 | static jobject android_media_tv_Tuner_open_dvr_recorder( |
| 905 | JNIEnv* /* env */, jobject /* thiz */, jlong /* bufferSize */) { |
| 906 | return NULL; |
| 907 | } |
| 908 | |
| 909 | static jobject android_media_tv_Tuner_open_dvr_playback( |
| 910 | JNIEnv* /* env */, jobject /* thiz */, jlong /* bufferSize */) { |
| 911 | return NULL; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 912 | } |
| 913 | |
shubang | 3425893 | 2019-12-27 13:59:23 -0800 | [diff] [blame] | 914 | static jobject android_media_tv_Tuner_get_demux_caps(JNIEnv*, jobject) { |
| 915 | return NULL; |
| 916 | } |
| 917 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 918 | static int android_media_tv_Tuner_attach_filter(JNIEnv *env, jobject dvr, jobject filter) { |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 919 | sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 920 | sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 921 | if (dvrSp == NULL || filterSp == NULL) { |
| 922 | return false; |
| 923 | } |
| 924 | Result result = dvrSp->attachFilter(filterSp); |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 925 | return (int) result; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 926 | } |
| 927 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 928 | static int android_media_tv_Tuner_detach_filter(JNIEnv *env, jobject dvr, jobject filter) { |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 929 | sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); |
shubang | 7648a3c | 2019-11-25 18:16:45 -0800 | [diff] [blame] | 930 | sp<IFilter> filterSp = getFilter(env, filter)->getIFilter(); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 931 | if (dvrSp == NULL || filterSp == NULL) { |
| 932 | return false; |
| 933 | } |
| 934 | Result result = dvrSp->detachFilter(filterSp); |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 935 | return (int) result; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 936 | } |
| 937 | |
shubang | 030afb5 | 2019-11-27 16:09:02 -0800 | [diff] [blame] | 938 | static int android_media_tv_Tuner_configure_dvr(JNIEnv *env, jobject dvr, jobject settings) { |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 939 | sp<Dvr> dvrSp = getDvr(env, dvr); |
| 940 | sp<IDvr> iDvrSp = dvrSp->getIDvr(); |
shubang | 030afb5 | 2019-11-27 16:09:02 -0800 | [diff] [blame] | 941 | if (dvrSp == NULL) { |
| 942 | ALOGD("Failed to configure dvr: dvr not found"); |
| 943 | return (int)Result::INVALID_STATE; |
| 944 | } |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 945 | Result result = iDvrSp->configure(getDvrSettings(env, settings)); |
| 946 | MQDescriptorSync<uint8_t> dvrMQDesc; |
| 947 | if (result == Result::SUCCESS) { |
| 948 | Result getQueueDescResult = Result::UNKNOWN_ERROR; |
| 949 | iDvrSp->getQueueDesc( |
| 950 | [&](Result r, const MQDescriptorSync<uint8_t>& desc) { |
| 951 | dvrMQDesc = desc; |
| 952 | getQueueDescResult = r; |
| 953 | ALOGD("getDvrQueueDesc"); |
| 954 | }); |
| 955 | if (getQueueDescResult == Result::SUCCESS) { |
| 956 | dvrSp->mDvrMQ = std::make_unique<DvrMQ>(dvrMQDesc, true); |
| 957 | EventFlag::createEventFlag( |
| 958 | dvrSp->mDvrMQ->getEventFlagWord(), &(dvrSp->mDvrMQEventFlag)); |
| 959 | } |
| 960 | } |
shubang | 030afb5 | 2019-11-27 16:09:02 -0800 | [diff] [blame] | 961 | return (int)result; |
| 962 | } |
| 963 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 964 | static int android_media_tv_Tuner_start_dvr(JNIEnv *env, jobject dvr) { |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 965 | sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 966 | if (dvrSp == NULL) { |
| 967 | ALOGD("Failed to start dvr: dvr not found"); |
| 968 | return false; |
| 969 | } |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 970 | Result result = dvrSp->start(); |
| 971 | return (int) result; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 972 | } |
| 973 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 974 | static int android_media_tv_Tuner_stop_dvr(JNIEnv *env, jobject dvr) { |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 975 | sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 976 | if (dvrSp == NULL) { |
| 977 | ALOGD("Failed to stop dvr: dvr not found"); |
| 978 | return false; |
| 979 | } |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 980 | Result result = dvrSp->stop(); |
| 981 | return (int) result; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 982 | } |
| 983 | |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 984 | static int android_media_tv_Tuner_flush_dvr(JNIEnv *env, jobject dvr) { |
shubang | 9e700ff | 2019-12-04 16:26:51 -0800 | [diff] [blame] | 985 | sp<IDvr> dvrSp = getDvr(env, dvr)->getIDvr(); |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 986 | if (dvrSp == NULL) { |
| 987 | ALOGD("Failed to flush dvr: dvr not found"); |
| 988 | return false; |
| 989 | } |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 990 | Result result = dvrSp->flush(); |
| 991 | return (int) result; |
| 992 | } |
| 993 | |
| 994 | static int android_media_tv_Tuner_close_dvr(JNIEnv*, jobject) { |
| 995 | return 0; |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 996 | } |
| 997 | |
shubang | 847fc0a | 2019-12-26 16:54:10 -0800 | [diff] [blame] | 998 | static int android_media_tv_Tuner_lnb_set_voltage(JNIEnv*, jobject, jint) { |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | static int android_media_tv_Tuner_lnb_set_tone(JNIEnv*, jobject, jint) { |
| 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | static int android_media_tv_Tuner_lnb_set_position(JNIEnv*, jobject, jint) { |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
| 1010 | static int android_media_tv_Tuner_lnb_send_diseqc_msg(JNIEnv*, jobject, jbyteArray) { |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | static int android_media_tv_Tuner_close_lnb(JNIEnv*, jobject) { |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1018 | static void android_media_tv_Tuner_dvr_set_fd(JNIEnv *env, jobject dvr, jobject jfd) { |
| 1019 | sp<Dvr> dvrSp = getDvr(env, dvr); |
| 1020 | if (dvrSp == NULL) { |
| 1021 | ALOGD("Failed to set FD for dvr: dvr not found"); |
| 1022 | } |
| 1023 | dvrSp->mFd = jniGetFDFromFileDescriptor(env, jfd); |
| 1024 | ALOGD("set fd = %d", dvrSp->mFd); |
| 1025 | } |
| 1026 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1027 | static jlong android_media_tv_Tuner_read_dvr(JNIEnv *env, jobject dvr, jlong size) { |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1028 | sp<Dvr> dvrSp = getDvr(env, dvr); |
| 1029 | if (dvrSp == NULL) { |
| 1030 | ALOGD("Failed to read dvr: dvr not found"); |
| 1031 | } |
| 1032 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1033 | long available = dvrSp->mDvrMQ->availableToWrite(); |
| 1034 | long write = std::min((long) size, available); |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1035 | |
| 1036 | DvrMQ::MemTransaction tx; |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1037 | long ret = 0; |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1038 | if (dvrSp->mDvrMQ->beginWrite(write, &tx)) { |
| 1039 | auto first = tx.getFirstRegion(); |
| 1040 | auto data = first.getAddress(); |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1041 | long length = first.getLength(); |
| 1042 | long firstToWrite = std::min(length, write); |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1043 | ret = read(dvrSp->mFd, data, firstToWrite); |
| 1044 | if (ret < firstToWrite) { |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1045 | ALOGW("[DVR] file to MQ, first region: %ld bytes to write, but %ld bytes written", |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1046 | firstToWrite, ret); |
| 1047 | } else if (firstToWrite < write) { |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1048 | ALOGD("[DVR] write second region: %ld bytes written, %ld bytes in total", ret, write); |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1049 | auto second = tx.getSecondRegion(); |
| 1050 | data = second.getAddress(); |
| 1051 | length = second.getLength(); |
| 1052 | int secondToWrite = std::min(length, write - firstToWrite); |
| 1053 | ret += read(dvrSp->mFd, data, secondToWrite); |
| 1054 | } |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1055 | ALOGD("[DVR] file to MQ: %ld bytes need to be written, %ld bytes written", write, ret); |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1056 | if (!dvrSp->mDvrMQ->commitWrite(ret)) { |
| 1057 | ALOGE("[DVR] Error: failed to commit write!"); |
| 1058 | } |
| 1059 | |
| 1060 | } else { |
| 1061 | ALOGE("dvrMq.beginWrite failed"); |
| 1062 | } |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1063 | return (jlong) ret; |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1064 | } |
| 1065 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1066 | static jlong android_media_tv_Tuner_read_dvr_from_array( |
| 1067 | JNIEnv /* *env */, jobject /* dvr */, jbyteArray /* bytes */, jlong /* offset */, |
| 1068 | jlong /* size */) { |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1069 | //TODO: impl |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1073 | static jlong android_media_tv_Tuner_write_dvr(JNIEnv *env, jobject dvr, jlong size) { |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 1074 | sp<Dvr> dvrSp = getDvr(env, dvr); |
| 1075 | if (dvrSp == NULL) { |
| 1076 | ALOGW("Failed to write dvr: dvr not found"); |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
| 1080 | if (dvrSp->mDvrMQ == NULL) { |
| 1081 | ALOGW("Failed to write dvr: dvr not configured"); |
| 1082 | return 0; |
| 1083 | } |
| 1084 | |
| 1085 | DvrMQ& dvrMq = dvrSp->getDvrMQ(); |
| 1086 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1087 | long available = dvrMq.availableToRead(); |
| 1088 | long toRead = std::min((long) size, available); |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 1089 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1090 | long ret = 0; |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 1091 | DvrMQ::MemTransaction tx; |
| 1092 | if (dvrMq.beginRead(toRead, &tx)) { |
| 1093 | auto first = tx.getFirstRegion(); |
| 1094 | auto data = first.getAddress(); |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1095 | long length = first.getLength(); |
| 1096 | long firstToRead = std::min(length, toRead); |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 1097 | ret = write(dvrSp->mFd, data, firstToRead); |
| 1098 | if (ret < firstToRead) { |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1099 | ALOGW("[DVR] MQ to file: %ld bytes read, but %ld bytes written", firstToRead, ret); |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 1100 | } else if (firstToRead < toRead) { |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1101 | ALOGD("[DVR] read second region: %ld bytes read, %ld bytes in total", ret, toRead); |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 1102 | auto second = tx.getSecondRegion(); |
| 1103 | data = second.getAddress(); |
| 1104 | length = second.getLength(); |
| 1105 | int secondToRead = toRead - firstToRead; |
| 1106 | ret += write(dvrSp->mFd, data, secondToRead); |
| 1107 | } |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1108 | ALOGD("[DVR] MQ to file: %ld bytes to be read, %ld bytes written", toRead, ret); |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 1109 | if (!dvrMq.commitRead(ret)) { |
| 1110 | ALOGE("[DVR] Error: failed to commit read!"); |
| 1111 | } |
| 1112 | |
| 1113 | } else { |
| 1114 | ALOGE("dvrMq.beginRead failed"); |
| 1115 | } |
| 1116 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1117 | return (jlong) ret; |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 1118 | } |
| 1119 | |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1120 | static jlong android_media_tv_Tuner_write_dvr_to_array( |
| 1121 | JNIEnv /* *env */, jobject /* dvr */, jbyteArray /* bytes */, jlong /* offset */, |
| 1122 | jlong /* size */) { |
shubang | 5f4ea35 | 2019-12-09 15:12:10 -0800 | [diff] [blame] | 1123 | //TODO: impl |
| 1124 | return 0; |
| 1125 | } |
shubang | ba21a7f | 2019-12-05 16:58:55 -0800 | [diff] [blame] | 1126 | |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 1127 | static const JNINativeMethod gTunerMethods[] = { |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 1128 | { "nativeInit", "()V", (void *)android_media_tv_Tuner_native_init }, |
| 1129 | { "nativeSetup", "()V", (void *)android_media_tv_Tuner_native_setup }, |
shubang | 7e849b0 | 2019-10-18 19:36:25 -0700 | [diff] [blame] | 1130 | { "nativeGetFrontendIds", "()Ljava/util/List;", |
| 1131 | (void *)android_media_tv_Tuner_get_frontend_ids }, |
| 1132 | { "nativeOpenFrontendById", "(I)Landroid/media/tv/tuner/Tuner$Frontend;", |
| 1133 | (void *)android_media_tv_Tuner_open_frontend_by_id }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1134 | { "nativeTune", "(ILandroid/media/tv/tuner/frontend/FrontendSettings;)I", |
shubang | 74bfd48 | 2019-10-29 19:10:22 -0700 | [diff] [blame] | 1135 | (void *)android_media_tv_Tuner_tune }, |
shubang | e65b686 | 2019-12-17 15:43:35 -0800 | [diff] [blame] | 1136 | { "nativeStopTune", "()I", (void *)android_media_tv_Tuner_stop_tune }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1137 | { "nativeScan", "(ILandroid/media/tv/tuner/frontend/FrontendSettings;I)I", |
shubang | d5b845f | 2019-12-11 15:29:09 -0800 | [diff] [blame] | 1138 | (void *)android_media_tv_Tuner_scan }, |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 1139 | { "nativeStopScan", "()I", (void *)android_media_tv_Tuner_stop_scan }, |
shubang | e65b686 | 2019-12-17 15:43:35 -0800 | [diff] [blame] | 1140 | { "nativeSetLnb", "(I)I", (void *)android_media_tv_Tuner_set_lnb }, |
| 1141 | { "nativeSetLna", "(Z)I", (void *)android_media_tv_Tuner_set_lna }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1142 | { "nativeGetFrontendStatus", "([I)Landroid/media/tv/tuner/frontend/FrontendStatus;", |
shubang | 1512ec1 | 2019-12-23 18:22:42 -0800 | [diff] [blame] | 1143 | (void *)android_media_tv_Tuner_get_frontend_status }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1144 | { "nativeGetAvSyncHwId", "(Landroid/media/tv/tuner/Tuner/filter/Filter;)I", |
shubang | 7343fee | 2019-12-27 12:02:08 -0800 | [diff] [blame] | 1145 | (void *)android_media_tv_Tuner_gat_av_sync_hw_id }, |
| 1146 | { "nativeGetAvSyncTime", "(I)J", (void *)android_media_tv_Tuner_gat_av_sync_time }, |
| 1147 | { "nativeConnectCiCam", "(I)I", (void *)android_media_tv_Tuner_connect_cicam }, |
| 1148 | { "nativeDisconnectCiCam", "()I", (void *)android_media_tv_Tuner_disconnect_cicam }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1149 | { "nativeGetFrontendInfo", "(I)Landroid/media/tv/tuner/FrontendInfo;", |
shubang | 95c1f75 | 2019-12-27 16:29:48 -0800 | [diff] [blame] | 1150 | (void *)android_media_tv_Tuner_get_frontend_info }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1151 | { "nativeOpenFilter", "(IIJ)Landroid/media/tv/tuner/Tuner/filter/Filter;", |
shubang | 6f473d6 | 2019-11-01 15:42:21 -0700 | [diff] [blame] | 1152 | (void *)android_media_tv_Tuner_open_filter }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1153 | { "nativeOpenTimeFilter", "()Landroid/media/tv/tuner/Tuner/filter/TimeFilter;", |
shubang | 4347e2e | 2019-12-13 17:20:40 -0800 | [diff] [blame] | 1154 | (void *)android_media_tv_Tuner_open_time_filter }, |
shubang | 760f031 | 2019-11-12 17:11:28 -0800 | [diff] [blame] | 1155 | { "nativeGetLnbIds", "()Ljava/util/List;", |
| 1156 | (void *)android_media_tv_Tuner_get_lnb_ids }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1157 | { "nativeOpenLnbById", "(I)Landroid/media/tv/tuner/Lnb;", |
shubang | 760f031 | 2019-11-12 17:11:28 -0800 | [diff] [blame] | 1158 | (void *)android_media_tv_Tuner_open_lnb_by_id }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1159 | { "nativeOpenDescrambler", "()Landroid/media/tv/tuner/Descrambler;", |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 1160 | (void *)android_media_tv_Tuner_open_descrambler }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1161 | { "nativeOpenDvrRecorder", "(J)Landroid/media/tv/tuner/dvr/DvrRecorder;", |
| 1162 | (void *)android_media_tv_Tuner_open_dvr_recorder }, |
| 1163 | { "nativeOpenDvrPlayback", "(J)Landroid/media/tv/tuner/dvr/DvrPlayback;", |
| 1164 | (void *)android_media_tv_Tuner_open_dvr_playback }, |
shubang | 3425893 | 2019-12-27 13:59:23 -0800 | [diff] [blame] | 1165 | { "nativeGetDemuxCapabilities", "()Landroid/media/tv/tuner/DemuxCapabilities;", |
| 1166 | (void *)android_media_tv_Tuner_get_demux_caps }, |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 1167 | }; |
| 1168 | |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 1169 | static const JNINativeMethod gFilterMethods[] = { |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1170 | { "nativeConfigureFilter", "(IILandroid/media/tv/tuner/filter/FilterConfiguration;)I", |
shubang | 75c8708 | 2019-11-15 11:26:56 -0800 | [diff] [blame] | 1171 | (void *)android_media_tv_Tuner_configure_filter }, |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 1172 | { "nativeGetId", "()I", (void *)android_media_tv_Tuner_get_filter_id }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1173 | { "nativeSetDataSource", "(Landroid/media/tv/tuner/filter/Filter;)I", |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 1174 | (void *)android_media_tv_Tuner_set_filter_data_source }, |
| 1175 | { "nativeStartFilter", "()I", (void *)android_media_tv_Tuner_start_filter }, |
| 1176 | { "nativeStopFilter", "()I", (void *)android_media_tv_Tuner_stop_filter }, |
| 1177 | { "nativeFlushFilter", "()I", (void *)android_media_tv_Tuner_flush_filter }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1178 | { "nativeRead", "([BJJ)I", (void *)android_media_tv_Tuner_read_filter_fmq }, |
Amy | 1b301f4 | 2020-01-02 11:07:56 -0800 | [diff] [blame] | 1179 | { "nativeClose", "()I", (void *)android_media_tv_Tuner_close_filter }, |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 1180 | }; |
| 1181 | |
shubang | 4347e2e | 2019-12-13 17:20:40 -0800 | [diff] [blame] | 1182 | static const JNINativeMethod gTimeFilterMethods[] = { |
| 1183 | { "nativeSetTimeStamp", "(J)I", (void *)android_media_tv_Tuner_time_filter_set_timestamp }, |
| 1184 | { "nativeClearTimeStamp", "()I", (void *)android_media_tv_Tuner_time_filter_clear_timestamp }, |
| 1185 | { "nativeGetTimeStamp", "()Ljava/lang/Long;", |
| 1186 | (void *)android_media_tv_Tuner_time_filter_get_timestamp }, |
| 1187 | { "nativeGetSourceTime", "()Ljava/lang/Long;", |
| 1188 | (void *)android_media_tv_Tuner_time_filter_get_source_time }, |
| 1189 | { "nativeClose", "()I", (void *)android_media_tv_Tuner_time_filter_close }, |
| 1190 | }; |
| 1191 | |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 1192 | static const JNINativeMethod gDescramblerMethods[] = { |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1193 | { "nativeAddPid", "(IILandroid/media/tv/tuner/filter/Filter;)I", |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 1194 | (void *)android_media_tv_Tuner_add_pid }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1195 | { "nativeRemovePid", "(IILandroid/media/tv/tuner/filter/Filter;)I", |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 1196 | (void *)android_media_tv_Tuner_remove_pid }, |
shubang | 99c8992 | 2019-12-17 17:33:15 -0800 | [diff] [blame] | 1197 | { "nativeSetKeyToken", "([B)I", (void *)android_media_tv_Tuner_set_key_token }, |
Amy | 1b301f4 | 2020-01-02 11:07:56 -0800 | [diff] [blame] | 1198 | { "nativeClose", "()I", (void *)android_media_tv_Tuner_close_descrambler }, |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 1199 | }; |
| 1200 | |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 1201 | static const JNINativeMethod gDvrMethods[] = { |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1202 | { "nativeAttachFilter", "(Landroid/media/tv/tuner/filter/Filter;)I", |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 1203 | (void *)android_media_tv_Tuner_attach_filter }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1204 | { "nativeDetachFilter", "(Landroid/media/tv/tuner/filter/Filter;)I", |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 1205 | (void *)android_media_tv_Tuner_detach_filter }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1206 | { "nativeConfigureDvr", "(Landroid/media/tv/tuner/dvr/DvrSettings;)I", |
shubang | 030afb5 | 2019-11-27 16:09:02 -0800 | [diff] [blame] | 1207 | (void *)android_media_tv_Tuner_configure_dvr }, |
shubang | 793e570 | 2019-12-26 15:15:46 -0800 | [diff] [blame] | 1208 | { "nativeStartDvr", "()I", (void *)android_media_tv_Tuner_start_dvr }, |
| 1209 | { "nativeStopDvr", "()I", (void *)android_media_tv_Tuner_stop_dvr }, |
| 1210 | { "nativeFlushDvr", "()I", (void *)android_media_tv_Tuner_flush_dvr }, |
| 1211 | { "nativeClose", "()I", (void *)android_media_tv_Tuner_close_dvr }, |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1212 | { "nativeSetFileDescriptor", "(I)V", (void *)android_media_tv_Tuner_dvr_set_fd }, |
| 1213 | }; |
| 1214 | |
| 1215 | static const JNINativeMethod gDvrRecorderMethods[] = { |
| 1216 | { "nativeWrite", "(J)J", (void *)android_media_tv_Tuner_write_dvr }, |
| 1217 | { "nativeWrite", "([BJJ)J", (void *)android_media_tv_Tuner_write_dvr_to_array }, |
| 1218 | }; |
| 1219 | |
| 1220 | static const JNINativeMethod gDvrPlaybackMethods[] = { |
| 1221 | { "nativeRead", "(J)J", (void *)android_media_tv_Tuner_read_dvr }, |
| 1222 | { "nativeRead", "([BJJ)J", (void *)android_media_tv_Tuner_read_dvr_from_array }, |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 1223 | }; |
| 1224 | |
shubang | 847fc0a | 2019-12-26 16:54:10 -0800 | [diff] [blame] | 1225 | static const JNINativeMethod gLnbMethods[] = { |
| 1226 | { "nativeSetVoltage", "(I)I", (void *)android_media_tv_Tuner_lnb_set_voltage }, |
| 1227 | { "nativeSetTone", "(I)I", (void *)android_media_tv_Tuner_lnb_set_tone }, |
| 1228 | { "nativeSetSatellitePosition", "(I)I", (void *)android_media_tv_Tuner_lnb_set_position }, |
| 1229 | { "nativeSendDiseqcMessage", "([B)I", (void *)android_media_tv_Tuner_lnb_send_diseqc_msg }, |
| 1230 | { "nativeClose", "()I", (void *)android_media_tv_Tuner_close_lnb }, |
| 1231 | }; |
| 1232 | |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 1233 | static bool register_android_media_tv_Tuner(JNIEnv *env) { |
| 1234 | if (AndroidRuntime::registerNativeMethods( |
| 1235 | env, "android/media/tv/tuner/Tuner", gTunerMethods, NELEM(gTunerMethods)) != JNI_OK) { |
| 1236 | ALOGE("Failed to register tuner native methods"); |
| 1237 | return false; |
| 1238 | } |
| 1239 | if (AndroidRuntime::registerNativeMethods( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1240 | env, "android/media/tv/tuner/filter/Filter", |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 1241 | gFilterMethods, |
| 1242 | NELEM(gFilterMethods)) != JNI_OK) { |
| 1243 | ALOGE("Failed to register filter native methods"); |
| 1244 | return false; |
| 1245 | } |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 1246 | if (AndroidRuntime::registerNativeMethods( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1247 | env, "android/media/tv/tuner/filter/TimeFilter", |
shubang | 4347e2e | 2019-12-13 17:20:40 -0800 | [diff] [blame] | 1248 | gTimeFilterMethods, |
| 1249 | NELEM(gTimeFilterMethods)) != JNI_OK) { |
| 1250 | ALOGE("Failed to register time filter native methods"); |
| 1251 | return false; |
| 1252 | } |
| 1253 | if (AndroidRuntime::registerNativeMethods( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1254 | env, "android/media/tv/tuner/Descrambler", |
shubang | 13f15e0 | 2019-11-04 17:51:02 -0800 | [diff] [blame] | 1255 | gDescramblerMethods, |
| 1256 | NELEM(gDescramblerMethods)) != JNI_OK) { |
| 1257 | ALOGE("Failed to register descrambler native methods"); |
| 1258 | return false; |
| 1259 | } |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 1260 | if (AndroidRuntime::registerNativeMethods( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1261 | env, "android/media/tv/tuner/dvr/Dvr", |
shubang | 4a0eddf | 2019-11-08 17:10:18 -0800 | [diff] [blame] | 1262 | gDvrMethods, |
| 1263 | NELEM(gDvrMethods)) != JNI_OK) { |
| 1264 | ALOGE("Failed to register dvr native methods"); |
| 1265 | return false; |
| 1266 | } |
shubang | 847fc0a | 2019-12-26 16:54:10 -0800 | [diff] [blame] | 1267 | if (AndroidRuntime::registerNativeMethods( |
shubang | d351b82 | 2020-01-22 17:29:18 -0800 | [diff] [blame] | 1268 | env, "android/media/tv/tuner/dvr/DvrRecorder", |
| 1269 | gDvrRecorderMethods, |
| 1270 | NELEM(gDvrRecorderMethods)) != JNI_OK) { |
| 1271 | ALOGE("Failed to register dvr recorder native methods"); |
| 1272 | return false; |
| 1273 | } |
| 1274 | if (AndroidRuntime::registerNativeMethods( |
| 1275 | env, "android/media/tv/tuner/dvr/DvrPlayback", |
| 1276 | gDvrPlaybackMethods, |
| 1277 | NELEM(gDvrPlaybackMethods)) != JNI_OK) { |
| 1278 | ALOGE("Failed to register dvr playback native methods"); |
| 1279 | return false; |
| 1280 | } |
| 1281 | if (AndroidRuntime::registerNativeMethods( |
| 1282 | env, "android/media/tv/tuner/Lnb", |
shubang | 847fc0a | 2019-12-26 16:54:10 -0800 | [diff] [blame] | 1283 | gLnbMethods, |
| 1284 | NELEM(gLnbMethods)) != JNI_OK) { |
| 1285 | ALOGE("Failed to register lnb native methods"); |
| 1286 | return false; |
| 1287 | } |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 1288 | return true; |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) |
| 1292 | { |
| 1293 | JNIEnv* env = NULL; |
| 1294 | jint result = -1; |
| 1295 | |
| 1296 | if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) { |
| 1297 | ALOGE("ERROR: GetEnv failed\n"); |
| 1298 | return result; |
| 1299 | } |
| 1300 | assert(env != NULL); |
| 1301 | |
shubang | d097790 | 2019-11-07 18:58:43 -0800 | [diff] [blame] | 1302 | if (!register_android_media_tv_Tuner(env)) { |
shubang | 8ab43b1 | 2019-10-18 15:55:55 -0700 | [diff] [blame] | 1303 | ALOGE("ERROR: Tuner native registration failed\n"); |
| 1304 | return result; |
| 1305 | } |
| 1306 | return JNI_VERSION_1_4; |
| 1307 | } |