diff --git a/media/java/android/media/tv/tuner/Lnb.java b/media/java/android/media/tv/tuner/Lnb.java index 5e9579430e112..59ef4b8903203 100644 --- a/media/java/android/media/tv/tuner/Lnb.java +++ b/media/java/android/media/tv/tuner/Lnb.java @@ -145,7 +145,6 @@ public class Lnb implements AutoCloseable { private static final String TAG = "Lnb"; - int mId; LnbCallback mCallback; Executor mExecutor; Tuner mTuner; @@ -162,9 +161,7 @@ public class Lnb implements AutoCloseable { private Boolean mIsClosed = false; private final Object mLock = new Object(); - private Lnb(int id) { - mId = id; - } + private Lnb() {} void setCallback(Executor executor, @Nullable LnbCallback callback, Tuner tuner) { mCallback = callback; diff --git a/media/java/android/media/tv/tuner/Tuner.java b/media/java/android/media/tv/tuner/Tuner.java index e449fd249e10d..9abd8fc141be4 100644 --- a/media/java/android/media/tv/tuner/Tuner.java +++ b/media/java/android/media/tv/tuner/Tuner.java @@ -552,7 +552,7 @@ public class Tuner implements AutoCloseable { private native int nativeStopTune(); private native int nativeScan(int settingsType, FrontendSettings settings, int scanType); private native int nativeStopScan(); - private native int nativeSetLnb(int lnbId); + private native int nativeSetLnb(Lnb lnb); private native int nativeSetLna(boolean enable); private native FrontendStatus nativeGetFrontendStatus(int[] statusTypes); private native Integer nativeGetAvSyncHwId(Filter filter); @@ -825,7 +825,7 @@ public class Tuner implements AutoCloseable { */ @Result private int setLnb(@NonNull Lnb lnb) { - return nativeSetLnb(lnb.mId); + return nativeSetLnb(lnb); } /** diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp index f9a84f740035a..5a18a4cb8b39e 100644 --- a/media/jni/android_media_tv_Tuner.cpp +++ b/media/jni/android_media_tv_Tuner.cpp @@ -209,59 +209,46 @@ void DestroyCallback(const C2Buffer * /* buf */, void *arg) { } namespace android { -/////////////// LnbCallback /////////////////////// -LnbCallback::LnbCallback(jobject lnbObj, LnbId id) : mId(id) { - JNIEnv *env = AndroidRuntime::getJNIEnv(); - mLnb = env->NewWeakGlobalRef(lnbObj); -} -LnbCallback::~LnbCallback() { - JNIEnv *env = AndroidRuntime::getJNIEnv(); - env->DeleteWeakGlobalRef(mLnb); - mLnb = NULL; -} +/////////////// LnbClientCallbackImpl /////////////////////// -Return LnbCallback::onEvent(LnbEventType lnbEventType) { - ALOGD("LnbCallback::onEvent, type=%d", lnbEventType); +void LnbClientCallbackImpl::onEvent(const LnbEventType lnbEventType) { + ALOGD("LnbClientCallbackImpl::onEvent, type=%d", lnbEventType); JNIEnv *env = AndroidRuntime::getJNIEnv(); env->CallVoidMethod( - mLnb, + mLnbObj, gFields.onLnbEventID, (jint)lnbEventType); - return Void(); } -Return LnbCallback::onDiseqcMessage(const hidl_vec& diseqcMessage) { - ALOGD("LnbCallback::onDiseqcMessage"); + +void LnbClientCallbackImpl::onDiseqcMessage(const hidl_vec& diseqcMessage) { + ALOGD("LnbClientCallbackImpl::onDiseqcMessage"); JNIEnv *env = AndroidRuntime::getJNIEnv(); jbyteArray array = env->NewByteArray(diseqcMessage.size()); env->SetByteArrayRegion( array, 0, diseqcMessage.size(), reinterpret_cast(diseqcMessage[0])); env->CallVoidMethod( - mLnb, + mLnbObj, gFields.onLnbDiseqcMessageID, array); - return Void(); } -/////////////// Lnb /////////////////////// +void LnbClientCallbackImpl::setLnb(jweak lnbObj) { + ALOGD("LnbClientCallbackImpl::setLnb"); + mLnbObj = lnbObj; +} -Lnb::Lnb(sp sp, jobject obj) : mLnbSp(sp) { +LnbClientCallbackImpl::~LnbClientCallbackImpl() { JNIEnv *env = AndroidRuntime::getJNIEnv(); - mLnbObj = env->NewWeakGlobalRef(obj); -} - -Lnb::~Lnb() { - JNIEnv *env = AndroidRuntime::getJNIEnv(); - env->DeleteWeakGlobalRef(mLnbObj); - mLnbObj = NULL; -} - -sp Lnb::getILnb() { - return mLnbSp; + if (mLnbObj != NULL) { + env->DeleteWeakGlobalRef(mLnbObj); + mLnbObj = NULL; + } } /////////////// DvrClientCallbackImpl /////////////////////// + void DvrClientCallbackImpl::onRecordStatus(RecordStatus status) { ALOGD("DvrClientCallbackImpl::onRecordStatus"); JNIEnv *env = AndroidRuntime::getJNIEnv(); @@ -1470,63 +1457,63 @@ jobject JTuner::getFrontendInfo(int id) { maxSymbolRate, acquireRange, exclusiveGroupId, statusCaps, jcaps); } -jobject JTuner::openLnbById(int id) { - sp iLnbSp; - Result r; - mTuner->openLnbById(id, [&](Result res, const sp& lnb) { - r = res; - iLnbSp = lnb; - }); - if (r != Result::SUCCESS || iLnbSp == nullptr) { - ALOGE("Failed to open lnb"); +jobject JTuner::openLnbByHandle(int handle) { + if (mTunerClient == NULL) { + return NULL; + } + + sp lnbClient; + sp callback = new LnbClientCallbackImpl(); + lnbClient = mTunerClient->openLnb(handle); + if (lnbClient == NULL) { + ALOGD("Failed to open lnb, handle = %d", handle); + return NULL; + } + + if (lnbClient->setCallback(callback) != Result::SUCCESS) { + ALOGD("Failed to set lnb callback"); return NULL; } - mLnb = iLnbSp; JNIEnv *env = AndroidRuntime::getJNIEnv(); jobject lnbObj = env->NewObject( env->FindClass("android/media/tv/tuner/Lnb"), - gFields.lnbInitID, - (jint) id); + gFields.lnbInitID); - sp lnbCb = new LnbCallback(lnbObj, id); - mLnb->setCallback(lnbCb); - - sp lnbSp = new Lnb(iLnbSp, lnbObj); - lnbSp->incStrong(lnbObj); - env->SetLongField(lnbObj, gFields.lnbContext, (jlong) lnbSp.get()); + lnbClient->incStrong(lnbObj); + env->SetLongField(lnbObj, gFields.lnbContext, (jlong)lnbClient.get()); + callback->setLnb(env->NewWeakGlobalRef(lnbObj)); return lnbObj; } jobject JTuner::openLnbByName(jstring name) { - JNIEnv *env = AndroidRuntime::getJNIEnv(); - std::string lnbName(env->GetStringUTFChars(name, nullptr)); - sp iLnbSp; - Result res; - LnbId id; - mTuner->openLnbByName(lnbName, [&](Result r, LnbId lnbId, const sp& lnb) { - res = r; - iLnbSp = lnb; - id = lnbId; - }); - if (res != Result::SUCCESS || iLnbSp == nullptr) { - ALOGE("Failed to open lnb"); + if (mTunerClient == NULL) { + return NULL; + } + + JNIEnv *env = AndroidRuntime::getJNIEnv(); + std::string lnbName(env->GetStringUTFChars(name, nullptr)); + sp lnbClient; + sp callback = new LnbClientCallbackImpl(); + lnbClient = mTunerClient->openLnbByName(lnbName); + if (lnbClient == NULL) { + ALOGD("Failed to open lnb by name, name = %s", lnbName.c_str()); + return NULL; + } + + if (lnbClient->setCallback(callback) != Result::SUCCESS) { + ALOGD("Failed to set lnb callback"); return NULL; } - mLnb = iLnbSp; jobject lnbObj = env->NewObject( env->FindClass("android/media/tv/tuner/Lnb"), - gFields.lnbInitID, - id); + gFields.lnbInitID); - sp lnbCb = new LnbCallback(lnbObj, id); - mLnb->setCallback(lnbCb); - - sp lnbSp = new Lnb(iLnbSp, lnbObj); - lnbSp->incStrong(lnbObj); - env->SetLongField(lnbObj, gFields.lnbContext, (jlong) lnbSp.get()); + lnbClient->incStrong(lnbObj); + env->SetLongField(lnbObj, gFields.lnbContext, (jlong)lnbClient.get()); + callback->setLnb(env->NewWeakGlobalRef(lnbObj)); return lnbObj; } @@ -1575,12 +1562,16 @@ int JTuner::stopScan() { return (int)result; } -int JTuner::setLnb(int id) { - if (mFe == NULL) { - ALOGE("frontend is not initialized"); +int JTuner::setLnb(sp lnbClient) { + if (mFeClient == NULL) { + ALOGE("frontend client is not initialized"); return (int)Result::INVALID_STATE; } - Result result = mFe->setLnb(id); + if (lnbClient == NULL) { + ALOGE("lnb is not initialized"); + return (int)Result::INVALID_STATE; + } + Result result = mFeClient->setLnb(lnbClient); return (int)result; } @@ -3199,6 +3190,10 @@ static sp getFilterClient(JNIEnv *env, jobject filter) { return (FilterClient *)env->GetLongField(filter, gFields.filterContext); } +static sp getLnbClient(JNIEnv *env, jobject lnb) { + return (LnbClient *)env->GetLongField(lnb, gFields.lnbContext); +} + static DvrSettings getDvrSettings(JNIEnv *env, jobject settings, bool isRecorder) { DvrSettings dvrSettings; jclass clazz = env->FindClass("android/media/tv/tuner/dvr/DvrSettings"); @@ -3262,7 +3257,7 @@ static void android_media_tv_Tuner_native_init(JNIEnv *env) { jclass lnbClazz = env->FindClass("android/media/tv/tuner/Lnb"); gFields.lnbContext = env->GetFieldID(lnbClazz, "mNativeContext", "J"); - gFields.lnbInitID = env->GetMethodID(lnbClazz, "", "(I)V"); + gFields.lnbInitID = env->GetMethodID(lnbClazz, "", "()V"); gFields.onLnbEventID = env->GetMethodID(lnbClazz, "onEvent", "(I)V"); gFields.onLnbDiseqcMessageID = env->GetMethodID(lnbClazz, "onDiseqcMessage", "([B)V"); @@ -3351,9 +3346,14 @@ static int android_media_tv_Tuner_stop_scan(JNIEnv *env, jobject thiz) { return tuner->stopScan(); } -static int android_media_tv_Tuner_set_lnb(JNIEnv *env, jobject thiz, jint id) { +static int android_media_tv_Tuner_set_lnb(JNIEnv *env, jobject thiz, jobject lnb) { sp tuner = getTuner(env, thiz); - return tuner->setLnb(id); + sp lnbClient = getLnbClient(env, lnb); + if (lnbClient == NULL) { + ALOGE("lnb is not initialized"); + return (int)Result::INVALID_STATE; + } + return tuner->setLnb(lnbClient); } static int android_media_tv_Tuner_set_lna(JNIEnv *env, jobject thiz, jboolean enable) { @@ -3410,8 +3410,7 @@ static jobject android_media_tv_Tuner_get_frontend_info(JNIEnv *env, jobject thi static jobject android_media_tv_Tuner_open_lnb_by_handle(JNIEnv *env, jobject thiz, jint handle) { sp tuner = getTuner(env, thiz); - uint32_t id = getResourceIdFromHandle(handle); - return tuner->openLnbById(id); + return tuner->openLnbByHandle(handle); } static jobject android_media_tv_Tuner_open_lnb_by_name(JNIEnv *env, jobject thiz, jstring name) { @@ -4259,42 +4258,38 @@ static jint android_media_tv_Tuner_close_dvr(JNIEnv* env, jobject dvr) { return (jint) dvrClient->close(); } -static sp getLnb(JNIEnv *env, jobject lnb) { - return (Lnb *)env->GetLongField(lnb, gFields.lnbContext); -} - static jint android_media_tv_Tuner_lnb_set_voltage(JNIEnv* env, jobject lnb, jint voltage) { - sp iLnbSp = getLnb(env, lnb)->getILnb(); - Result r = iLnbSp->setVoltage(static_cast(voltage)); + sp lnbClient = getLnbClient(env, lnb); + Result r = lnbClient->setVoltage(static_cast(voltage)); return (jint) r; } static int android_media_tv_Tuner_lnb_set_tone(JNIEnv* env, jobject lnb, jint tone) { - sp iLnbSp = getLnb(env, lnb)->getILnb(); - Result r = iLnbSp->setTone(static_cast(tone)); + sp lnbClient = getLnbClient(env, lnb); + Result r = lnbClient->setTone(static_cast(tone)); return (jint) r; } static int android_media_tv_Tuner_lnb_set_position(JNIEnv* env, jobject lnb, jint position) { - sp iLnbSp = getLnb(env, lnb)->getILnb(); - Result r = iLnbSp->setSatellitePosition(static_cast(position)); + sp lnbClient = getLnbClient(env, lnb); + Result r = lnbClient->setSatellitePosition(static_cast(position)); return (jint) r; } static int android_media_tv_Tuner_lnb_send_diseqc_msg(JNIEnv* env, jobject lnb, jbyteArray msg) { - sp iLnbSp = getLnb(env, lnb)->getILnb(); + sp lnbClient = getLnbClient(env, lnb); int size = env->GetArrayLength(msg); std::vector v(size); env->GetByteArrayRegion(msg, 0, size, reinterpret_cast(&v[0])); - Result r = iLnbSp->sendDiseqcMessage(v); + Result r = lnbClient->sendDiseqcMessage(v); return (jint) r; } static int android_media_tv_Tuner_close_lnb(JNIEnv* env, jobject lnb) { - sp lnbSp = getLnb(env, lnb); - Result r = lnbSp->getILnb()->close(); + sp lnbClient = getLnbClient(env, lnb); + Result r = lnbClient->close(); if (r == Result::SUCCESS) { - lnbSp->decStrong(lnb); + lnbClient->decStrong(lnb); env->SetLongField(lnb, gFields.lnbContext, 0); } return (jint) r; @@ -4433,7 +4428,7 @@ static const JNINativeMethod gTunerMethods[] = { { "nativeScan", "(ILandroid/media/tv/tuner/frontend/FrontendSettings;I)I", (void *)android_media_tv_Tuner_scan }, { "nativeStopScan", "()I", (void *)android_media_tv_Tuner_stop_scan }, - { "nativeSetLnb", "(I)I", (void *)android_media_tv_Tuner_set_lnb }, + { "nativeSetLnb", "(Landroid/media/tv/tuner/Lnb;)I", (void *)android_media_tv_Tuner_set_lnb }, { "nativeSetLna", "(Z)I", (void *)android_media_tv_Tuner_set_lna }, { "nativeGetFrontendStatus", "([I)Landroid/media/tv/tuner/frontend/FrontendStatus;", (void *)android_media_tv_Tuner_get_frontend_status }, diff --git a/media/jni/android_media_tv_Tuner.h b/media/jni/android_media_tv_Tuner.h index 8fffb2a22a304..b0613d4b5ee4b 100644 --- a/media/jni/android_media_tv_Tuner.h +++ b/media/jni/android_media_tv_Tuner.h @@ -35,10 +35,13 @@ #include #include "tuner/DemuxClient.h" +#include "tuner/DescramblerClient.h" #include "tuner/FilterClient.h" #include "tuner/FilterClientCallback.h" #include "tuner/FrontendClient.h" #include "tuner/FrontendClientCallback.h" +#include "tuner/LnbClient.h" +#include "tuner/LnbClientCallback.h" #include "tuner/TunerClient.h" #include "jni.h" @@ -87,13 +90,14 @@ using MQ = MessageQueue; namespace android { -struct LnbCallback : public ILnbCallback { - LnbCallback(jweak tunerObj, LnbId id); - ~LnbCallback(); - virtual Return onEvent(LnbEventType lnbEventType); - virtual Return onDiseqcMessage(const hidl_vec& diseqcMessage); - jweak mLnb; - LnbId mId; +struct LnbClientCallbackImpl : public LnbClientCallback { + ~LnbClientCallbackImpl(); + virtual void onEvent(LnbEventType lnbEventType); + virtual void onDiseqcMessage(const hidl_vec& diseqcMessage); + + void setLnb(jweak lnbObj); +private: + jweak mLnbObj; }; struct Lnb : public RefBase { @@ -215,9 +219,9 @@ struct JTuner : public RefBase { int scan(const FrontendSettings& settings, FrontendScanType scanType, const FrontendSettingsExt1_1& settingsExt1_1); int stopScan(); - int setLnb(int id); + int setLnb(sp lnbClient); int setLna(bool enable); - jobject openLnbById(int id); + jobject openLnbByHandle(int handle); jobject openLnbByName(jstring name); jobject openFilter(DemuxFilterType type, int bufferSize); jobject openTimeFilter(); @@ -246,8 +250,7 @@ private: sp<::android::hardware::tv::tuner::V1_1::IFrontend> mFe_1_1; sp mFeClient; int mFeId; - // TODO: remove after migrate to client lib - sp mLnb; + sp mLnbClient; // TODO: remove after migrate to client lib sp mDemux; sp mDemuxClient; diff --git a/media/jni/tuner/FrontendClient.cpp b/media/jni/tuner/FrontendClient.cpp index b6225cf5033a1..9dd4df762198c 100644 --- a/media/jni/tuner/FrontendClient.cpp +++ b/media/jni/tuner/FrontendClient.cpp @@ -99,6 +99,21 @@ Result FrontendClient::stopTune() { return Result::INVALID_STATE; } +Result FrontendClient::setLnb(sp lnbClient) { + if (mTunerFrontend != NULL) { + // TODO: handle error message. + /*mTunerFrontend->setLnb(lnbClient->getAidlLnb()); + return Result::SUCCESS;*/ + } + + if (mFrontend != NULL) { + Result result = mFrontend->setLnb(lnbClient->getId()); + return result; + } + + return Result::INVALID_STATE; +} + Result FrontendClient::close() { if (mTunerFrontend != NULL) { // TODO: handle error message. diff --git a/media/jni/tuner/FrontendClient.h b/media/jni/tuner/FrontendClient.h index 265e14f5ddd07..b24f944638e76 100644 --- a/media/jni/tuner/FrontendClient.h +++ b/media/jni/tuner/FrontendClient.h @@ -24,6 +24,7 @@ #include #include "FrontendClientCallback.h" +#include "LnbClient.h" using Status = ::ndk::ScopedAStatus; @@ -126,6 +127,11 @@ public: */ Result stopTune(); + /** + * Sets Low-Noise Block downconverter (LNB) for satellite frontend. + */ + Result setLnb(sp lnbClient); + /** * Close Frontend. */ diff --git a/media/jni/tuner/LnbClient.cpp b/media/jni/tuner/LnbClient.cpp index c9f9f849df2f7..7f3916fe634d6 100644 --- a/media/jni/tuner/LnbClient.cpp +++ b/media/jni/tuner/LnbClient.cpp @@ -30,11 +30,13 @@ namespace android { // TODO: pending aidl interface LnbClient::LnbClient() { //mTunerLnb = tunerLnb; + mId = -1; } LnbClient::~LnbClient() { //mTunerLnb = NULL; mLnb = NULL; + mId = -1; } // TODO: remove after migration to Tuner Service is done. @@ -42,28 +44,66 @@ void LnbClient::setHidlLnb(sp lnb) { mLnb = lnb; } -Result LnbClient::setCallback(sp /*cb*/) { - return Result::SUCCESS; +Result LnbClient::setCallback(sp cb) { + // TODO: pending aidl interface + /*if (mTunerFrontend != NULL) { + mAidlCallback = ::ndk::SharedRefBase::make(cb); + mTunerLnb->setCallback(mAidlCallback); + return Result::SUCCESS; + }*/ + + mHidlCallback = new HidlLnbCallback(cb); + return mLnb->setCallback(mHidlCallback); } -Result LnbClient::setVoltage(int /*voltage*/) { - return Result::SUCCESS; +Result LnbClient::setVoltage(LnbVoltage voltage) { + // TODO: pending aidl interface + + if (mLnb != NULL) { + return mLnb->setVoltage(voltage); + } + + return Result::INVALID_STATE; } -Result LnbClient::setTone(int /*tone*/) { - return Result::SUCCESS; +Result LnbClient::setTone(LnbTone tone) { + // TODO: pending aidl interface + + if (mLnb != NULL) { + return mLnb->setTone(tone); + } + + return Result::INVALID_STATE; } -Result LnbClient::setSatellitePosition(int /*position*/) { - return Result::SUCCESS; +Result LnbClient::setSatellitePosition(LnbPosition position) { + // TODO: pending aidl interface + + if (mLnb != NULL) { + return mLnb->setSatellitePosition(position); + } + + return Result::INVALID_STATE; } -Result LnbClient::sendDiseqcMessage(vector /*diseqcMessage*/) { - return Result::SUCCESS; +Result LnbClient::sendDiseqcMessage(vector diseqcMessage) { + // TODO: pending aidl interface + + if (mLnb != NULL) { + return mLnb->sendDiseqcMessage(diseqcMessage); + } + + return Result::INVALID_STATE; } Result LnbClient::close() { - return Result::SUCCESS; + // TODO: pending aidl interface + + if (mLnb != NULL) { + return mLnb->close(); + } + + return Result::INVALID_STATE; } /////////////// ILnbCallback /////////////////////// diff --git a/media/jni/tuner/LnbClient.h b/media/jni/tuner/LnbClient.h index c548777ad40ca..533a99678efe7 100644 --- a/media/jni/tuner/LnbClient.h +++ b/media/jni/tuner/LnbClient.h @@ -31,6 +31,10 @@ using ::android::hardware::Void; using ::android::hardware::hidl_vec; using ::android::hardware::tv::tuner::V1_0::ILnb; using ::android::hardware::tv::tuner::V1_0::ILnbCallback; +using ::android::hardware::tv::tuner::V1_0::LnbId; +using ::android::hardware::tv::tuner::V1_0::LnbPosition; +using ::android::hardware::tv::tuner::V1_0::LnbTone; +using ::android::hardware::tv::tuner::V1_0::LnbVoltage; using ::android::hardware::tv::tuner::V1_0::Result; using namespace std; @@ -79,17 +83,17 @@ public: /** * Set the lnb's power voltage. */ - Result setVoltage(int voltage); + Result setVoltage(LnbVoltage voltage); /** * Set the lnb's tone mode. */ - Result setTone(int tone); + Result setTone(LnbTone tone); /** * Select the lnb's position. */ - Result setSatellitePosition(int position); + Result setSatellitePosition(LnbPosition position); /** * Sends DiSEqC (Digital Satellite Equipment Control) message. @@ -101,6 +105,10 @@ public: */ Result close(); + //shared_ptr getAidlLnb() { return mTunerLnb; } + void setId(LnbId id) { mId = id; } + LnbId getId() { return mId; } + private: /** * An AIDL Tuner Lnb Singleton assigned at the first time the Tuner Client @@ -115,6 +123,11 @@ private: * Default null when the HAL service does not exist. */ sp mLnb; + + //shared_ptr mAidlCallback; + sp mHidlCallback; + + LnbId mId; }; } // namespace android diff --git a/media/jni/tuner/TunerClient.cpp b/media/jni/tuner/TunerClient.cpp index 67a559cc440ee..69cd3d332c7f6 100644 --- a/media/jni/tuner/TunerClient.cpp +++ b/media/jni/tuner/TunerClient.cpp @@ -180,11 +180,49 @@ sp TunerClient::openDescrambler(int /*descramblerHandle*/) { return NULL; } -sp TunerClient::openLnb(int /*lnbHandle*/) { +sp TunerClient::openLnb(int lnbHandle) { + if (mTunerService != NULL) { + // TODO: handle error code + /*shared_ptr tunerLnb; + mTunerService->openLnb(demuxHandle, &tunerLnb); + return new LnbClient(tunerLnb);*/ + } + + if (mTuner != NULL) { + int id = getResourceIdFromHandle(lnbHandle, LNB); + // TODO: pending aidl interface + sp lnbClient = new LnbClient(); + sp hidlLnb = openHidlLnbById(id); + if (hidlLnb != NULL) { + lnbClient->setHidlLnb(hidlLnb); + lnbClient->setId(id); + return lnbClient; + } + } + return NULL; } -sp TunerClient::openLnbByName(string /*lnbName*/) { +sp TunerClient::openLnbByName(string lnbName) { + if (mTunerService != NULL) { + // TODO: handle error code + /*shared_ptr tunerLnb; + mTunerService->openLnbByName(lnbName, &tunerLnb); + return new LnbClient(tunerLnb);*/ + } + + if (mTuner != NULL) { + // TODO: pending aidl interface + sp lnbClient = new LnbClient(); + LnbId id; + sp hidlLnb = openHidlLnbByName(lnbName, id); + if (hidlLnb != NULL) { + lnbClient->setHidlLnb(hidlLnb); + lnbClient->setId(id); + return lnbClient; + } + } + return NULL; } @@ -249,6 +287,37 @@ sp TunerClient::openHidlDemux() { return demux; } +sp TunerClient::openHidlLnbById(int id) { + sp lnb; + Result res; + + mTuner->openLnbById(id, [&](Result r, const sp& lnbSp) { + res = r; + lnb = lnbSp; + }); + if (res != Result::SUCCESS || lnb == nullptr) { + ALOGE("Failed to open lnb by id"); + return NULL; + } + return lnb; +} + +sp TunerClient::openHidlLnbByName(string name, LnbId& lnbId) { + sp lnb; + Result res; + + mTuner->openLnbByName(name, [&](Result r, LnbId id, const sp& lnbSp) { + res = r; + lnb = lnbSp; + lnbId = id; + }); + if (res != Result::SUCCESS || lnb == nullptr) { + ALOGE("Failed to open lnb by name"); + return NULL; + } + return lnb; +} + FrontendInfo TunerClient::FrontendInfoAidlToHidl(TunerServiceFrontendInfo aidlFrontendInfo) { FrontendInfo hidlFrontendInfo { .type = static_cast(aidlFrontendInfo.type), diff --git a/media/jni/tuner/TunerClient.h b/media/jni/tuner/TunerClient.h index 98ae24df8d4a5..06ba7a552cfbd 100644 --- a/media/jni/tuner/TunerClient.h +++ b/media/jni/tuner/TunerClient.h @@ -133,6 +133,8 @@ private: sp openHidlFrontendById(int id); sp openHidlDemux(); Result getHidlFrontendInfo(int id, FrontendInfo& info); + sp openHidlLnbById(int id); + sp openHidlLnbByName(string name, LnbId& lnbId); FrontendInfo FrontendInfoAidlToHidl(TunerServiceFrontendInfo aidlFrontendInfo); int getResourceIdFromHandle(int handle, int resourceType);