Merge "Tuner JNI: LnbCallback" into rvc-dev am: d0e4132654 am: 226a97d573
Change-Id: I4a509c97cedc77e12e290ee953712bb8a89c0a1e
This commit is contained in:
@@ -20,12 +20,12 @@ import android.annotation.IntDef;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.content.Context;
|
|
||||||
import android.hardware.tv.tuner.V1_0.Constants;
|
import android.hardware.tv.tuner.V1_0.Constants;
|
||||||
import android.media.tv.tuner.Tuner.Result;
|
import android.media.tv.tuner.Tuner.Result;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LNB (low-noise block downconverter) for satellite tuner.
|
* LNB (low-noise block downconverter) for satellite tuner.
|
||||||
@@ -145,7 +145,8 @@ public class Lnb implements AutoCloseable {
|
|||||||
|
|
||||||
int mId;
|
int mId;
|
||||||
LnbCallback mCallback;
|
LnbCallback mCallback;
|
||||||
Context mContext;
|
Executor mExecutor;
|
||||||
|
|
||||||
|
|
||||||
private native int nativeSetVoltage(int voltage);
|
private native int nativeSetVoltage(int voltage);
|
||||||
private native int nativeSetTone(int tone);
|
private native int nativeSetTone(int tone);
|
||||||
@@ -159,10 +160,20 @@ public class Lnb implements AutoCloseable {
|
|||||||
mId = id;
|
mId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setCallback(@Nullable LnbCallback callback) {
|
void setCallback(Executor executor, @Nullable LnbCallback callback) {
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
if (mCallback == null) {
|
mExecutor = executor;
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
private void onEvent(int eventType) {
|
||||||
|
if (mExecutor != null && mCallback != null) {
|
||||||
|
mExecutor.execute(() -> mCallback.onEvent(eventType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDiseqcMessage(byte[] diseqcMessage) {
|
||||||
|
if (mExecutor != null && mCallback != null) {
|
||||||
|
mExecutor.execute(() -> mCallback.onDiseqcMessage(diseqcMessage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,6 +229,9 @@ public class Lnb implements AutoCloseable {
|
|||||||
* Releases the LNB instance.
|
* Releases the LNB instance.
|
||||||
*/
|
*/
|
||||||
public void close() {
|
public void close() {
|
||||||
nativeClose();
|
int res = nativeClose();
|
||||||
|
if (res != Tuner.RESULT_SUCCESS) {
|
||||||
|
TunerUtils.throwExceptionForResult(res, "Failed to close LNB");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -829,6 +829,9 @@ public class Tuner implements AutoCloseable {
|
|||||||
Objects.requireNonNull(executor, "executor must not be null");
|
Objects.requireNonNull(executor, "executor must not be null");
|
||||||
Objects.requireNonNull(cb, "LnbCallback must not be null");
|
Objects.requireNonNull(cb, "LnbCallback must not be null");
|
||||||
checkResource(TunerResourceManager.TUNER_RESOURCE_TYPE_LNB);
|
checkResource(TunerResourceManager.TUNER_RESOURCE_TYPE_LNB);
|
||||||
|
if (mLnb != null) {
|
||||||
|
mLnb.setCallback(executor, cb);
|
||||||
|
}
|
||||||
return mLnb;
|
return mLnb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -847,7 +850,11 @@ public class Tuner implements AutoCloseable {
|
|||||||
Objects.requireNonNull(name, "LNB name must not be null");
|
Objects.requireNonNull(name, "LNB name must not be null");
|
||||||
Objects.requireNonNull(executor, "executor must not be null");
|
Objects.requireNonNull(executor, "executor must not be null");
|
||||||
Objects.requireNonNull(cb, "LnbCallback must not be null");
|
Objects.requireNonNull(cb, "LnbCallback must not be null");
|
||||||
return nativeOpenLnbByName(name);
|
mLnb = nativeOpenLnbByName(name);
|
||||||
|
if (mLnb != null) {
|
||||||
|
mLnb.setCallback(executor, cb);
|
||||||
|
}
|
||||||
|
return mLnb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean requestLnb() {
|
private boolean requestLnb() {
|
||||||
@@ -872,12 +879,6 @@ public class Tuner implements AutoCloseable {
|
|||||||
return nativeOpenTimeFilter();
|
return nativeOpenTimeFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLnbEvent(int eventType) {
|
|
||||||
if (mHandler != null) {
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_ON_LNB_EVENT, eventType, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a Descrambler in tuner.
|
* Opens a Descrambler in tuner.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ public final class TunerUtils {
|
|||||||
msg = "";
|
msg = "";
|
||||||
}
|
}
|
||||||
switch (r) {
|
switch (r) {
|
||||||
|
case Tuner.RESULT_SUCCESS:
|
||||||
|
return;
|
||||||
case Tuner.RESULT_INVALID_ARGUMENT:
|
case Tuner.RESULT_INVALID_ARGUMENT:
|
||||||
throw new IllegalArgumentException(msg);
|
throw new IllegalArgumentException(msg);
|
||||||
case Tuner.RESULT_INVALID_STATE:
|
case Tuner.RESULT_INVALID_STATE:
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class TimeFilter implements AutoCloseable {
|
|||||||
@Result
|
@Result
|
||||||
public int clearTimestamp() {
|
public int clearTimestamp() {
|
||||||
int res = nativeClearTimestamp();
|
int res = nativeClearTimestamp();
|
||||||
if (res == 0) {
|
if (res == Tuner.RESULT_SUCCESS) {
|
||||||
mEnable = false;
|
mEnable = false;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ struct fields_t {
|
|||||||
jmethodID onFilterEventID;
|
jmethodID onFilterEventID;
|
||||||
jmethodID lnbInitID;
|
jmethodID lnbInitID;
|
||||||
jmethodID onLnbEventID;
|
jmethodID onLnbEventID;
|
||||||
|
jmethodID onLnbDiseqcMessageID;
|
||||||
jmethodID onDvrRecordStatusID;
|
jmethodID onDvrRecordStatusID;
|
||||||
jmethodID onDvrPlaybackStatusID;
|
jmethodID onDvrPlaybackStatusID;
|
||||||
jmethodID descramblerInitID;
|
jmethodID descramblerInitID;
|
||||||
@@ -170,19 +171,31 @@ static int IP_V6_LENGTH = 16;
|
|||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
/////////////// LnbCallback ///////////////////////
|
/////////////// LnbCallback ///////////////////////
|
||||||
LnbCallback::LnbCallback(jweak tunerObj, LnbId id) : mObject(tunerObj), mId(id) {}
|
LnbCallback::LnbCallback(jobject lnbObj, LnbId id) : mId(id) {
|
||||||
|
JNIEnv *env = AndroidRuntime::getJNIEnv();
|
||||||
|
mLnb = env->NewWeakGlobalRef(lnbObj);
|
||||||
|
}
|
||||||
|
|
||||||
Return<void> LnbCallback::onEvent(LnbEventType lnbEventType) {
|
Return<void> LnbCallback::onEvent(LnbEventType lnbEventType) {
|
||||||
ALOGD("LnbCallback::onEvent, type=%d", lnbEventType);
|
ALOGD("LnbCallback::onEvent, type=%d", lnbEventType);
|
||||||
JNIEnv *env = AndroidRuntime::getJNIEnv();
|
JNIEnv *env = AndroidRuntime::getJNIEnv();
|
||||||
env->CallVoidMethod(
|
env->CallVoidMethod(
|
||||||
mObject,
|
mLnb,
|
||||||
gFields.onLnbEventID,
|
gFields.onLnbEventID,
|
||||||
(jint)lnbEventType);
|
(jint)lnbEventType);
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
Return<void> LnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& /*diseqcMessage*/) {
|
Return<void> LnbCallback::onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage) {
|
||||||
ALOGD("LnbCallback::onDiseqcMessage");
|
ALOGD("LnbCallback::onDiseqcMessage");
|
||||||
|
JNIEnv *env = AndroidRuntime::getJNIEnv();
|
||||||
|
jbyteArray array = env->NewByteArray(diseqcMessage.size());
|
||||||
|
env->SetByteArrayRegion(
|
||||||
|
array, 0, diseqcMessage.size(), reinterpret_cast<jbyte*>(diseqcMessage[0]));
|
||||||
|
|
||||||
|
env->CallVoidMethod(
|
||||||
|
mLnb,
|
||||||
|
gFields.onLnbDiseqcMessageID,
|
||||||
|
array);
|
||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -875,6 +888,10 @@ jobject JTuner::openFrontendById(int id) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mFe = fe;
|
mFe = fe;
|
||||||
|
mFeId = id;
|
||||||
|
if (mDemux != NULL) {
|
||||||
|
mDemux->setFrontendDataSource(mFeId);
|
||||||
|
}
|
||||||
sp<FrontendCallback> feCb = new FrontendCallback(mObject, id);
|
sp<FrontendCallback> feCb = new FrontendCallback(mObject, id);
|
||||||
fe->setCallback(feCb);
|
fe->setCallback(feCb);
|
||||||
|
|
||||||
@@ -1089,16 +1106,16 @@ jobject JTuner::getLnbIds() {
|
|||||||
|
|
||||||
jobject JTuner::openLnbById(int id) {
|
jobject JTuner::openLnbById(int id) {
|
||||||
sp<ILnb> iLnbSp;
|
sp<ILnb> iLnbSp;
|
||||||
mTuner->openLnbById(id, [&](Result, const sp<ILnb>& lnb) {
|
Result r;
|
||||||
|
mTuner->openLnbById(id, [&](Result res, const sp<ILnb>& lnb) {
|
||||||
|
r = res;
|
||||||
iLnbSp = lnb;
|
iLnbSp = lnb;
|
||||||
});
|
});
|
||||||
if (iLnbSp == nullptr) {
|
if (r != Result::SUCCESS || iLnbSp == nullptr) {
|
||||||
ALOGE("Failed to open lnb");
|
ALOGE("Failed to open lnb");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mLnb = iLnbSp;
|
mLnb = iLnbSp;
|
||||||
sp<LnbCallback> lnbCb = new LnbCallback(mObject, id);
|
|
||||||
mLnb->setCallback(lnbCb);
|
|
||||||
|
|
||||||
JNIEnv *env = AndroidRuntime::getJNIEnv();
|
JNIEnv *env = AndroidRuntime::getJNIEnv();
|
||||||
jobject lnbObj = env->NewObject(
|
jobject lnbObj = env->NewObject(
|
||||||
@@ -1106,6 +1123,9 @@ jobject JTuner::openLnbById(int id) {
|
|||||||
gFields.lnbInitID,
|
gFields.lnbInitID,
|
||||||
(jint) id);
|
(jint) id);
|
||||||
|
|
||||||
|
sp<LnbCallback> lnbCb = new LnbCallback(lnbObj, id);
|
||||||
|
mLnb->setCallback(lnbCb);
|
||||||
|
|
||||||
sp<Lnb> lnbSp = new Lnb(iLnbSp, lnbObj);
|
sp<Lnb> lnbSp = new Lnb(iLnbSp, lnbObj);
|
||||||
lnbSp->incStrong(lnbObj);
|
lnbSp->incStrong(lnbObj);
|
||||||
env->SetLongField(lnbObj, gFields.lnbContext, (jlong) lnbSp.get());
|
env->SetLongField(lnbObj, gFields.lnbContext, (jlong) lnbSp.get());
|
||||||
@@ -1129,14 +1149,15 @@ jobject JTuner::openLnbByName(jstring name) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
mLnb = iLnbSp;
|
mLnb = iLnbSp;
|
||||||
sp<LnbCallback> lnbCb = new LnbCallback(mObject, id);
|
|
||||||
mLnb->setCallback(lnbCb);
|
|
||||||
|
|
||||||
jobject lnbObj = env->NewObject(
|
jobject lnbObj = env->NewObject(
|
||||||
env->FindClass("android/media/tv/tuner/Lnb"),
|
env->FindClass("android/media/tv/tuner/Lnb"),
|
||||||
gFields.lnbInitID,
|
gFields.lnbInitID,
|
||||||
id);
|
id);
|
||||||
|
|
||||||
|
sp<LnbCallback> lnbCb = new LnbCallback(lnbObj, id);
|
||||||
|
mLnb->setCallback(lnbCb);
|
||||||
|
|
||||||
sp<Lnb> lnbSp = new Lnb(iLnbSp, lnbObj);
|
sp<Lnb> lnbSp = new Lnb(iLnbSp, lnbObj);
|
||||||
lnbSp->incStrong(lnbObj);
|
lnbSp->incStrong(lnbObj);
|
||||||
env->SetLongField(lnbObj, gFields.lnbContext, (jlong) lnbSp.get());
|
env->SetLongField(lnbObj, gFields.lnbContext, (jlong) lnbSp.get());
|
||||||
@@ -1206,12 +1227,21 @@ Result JTuner::openDemux() {
|
|||||||
return Result::SUCCESS;
|
return Result::SUCCESS;
|
||||||
}
|
}
|
||||||
Result res;
|
Result res;
|
||||||
|
uint32_t id;
|
||||||
|
sp<IDemux> demuxSp;
|
||||||
mTuner->openDemux([&](Result r, uint32_t demuxId, const sp<IDemux>& demux) {
|
mTuner->openDemux([&](Result r, uint32_t demuxId, const sp<IDemux>& demux) {
|
||||||
mDemux = demux;
|
demuxSp = demux;
|
||||||
mDemuxId = demuxId;
|
id = demuxId;
|
||||||
res = r;
|
res = r;
|
||||||
ALOGD("open demux, id = %d", demuxId);
|
ALOGD("open demux, id = %d", demuxId);
|
||||||
});
|
});
|
||||||
|
if (res == Result::SUCCESS) {
|
||||||
|
mDemux = demuxSp;
|
||||||
|
mDemuxId = id;
|
||||||
|
if (mFe != NULL) {
|
||||||
|
mDemux->setFrontendDataSource(mFeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2242,8 +2272,6 @@ static void android_media_tv_Tuner_native_init(JNIEnv *env) {
|
|||||||
|
|
||||||
gFields.onFrontendEventID = env->GetMethodID(clazz, "onFrontendEvent", "(I)V");
|
gFields.onFrontendEventID = env->GetMethodID(clazz, "onFrontendEvent", "(I)V");
|
||||||
|
|
||||||
gFields.onLnbEventID = env->GetMethodID(clazz, "onLnbEvent", "(I)V");
|
|
||||||
|
|
||||||
jclass frontendClazz = env->FindClass("android/media/tv/tuner/Tuner$Frontend");
|
jclass frontendClazz = env->FindClass("android/media/tv/tuner/Tuner$Frontend");
|
||||||
gFields.frontendInitID =
|
gFields.frontendInitID =
|
||||||
env->GetMethodID(frontendClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;I)V");
|
env->GetMethodID(frontendClazz, "<init>", "(Landroid/media/tv/tuner/Tuner;I)V");
|
||||||
@@ -2251,6 +2279,8 @@ static void android_media_tv_Tuner_native_init(JNIEnv *env) {
|
|||||||
jclass lnbClazz = env->FindClass("android/media/tv/tuner/Lnb");
|
jclass lnbClazz = env->FindClass("android/media/tv/tuner/Lnb");
|
||||||
gFields.lnbContext = env->GetFieldID(lnbClazz, "mNativeContext", "J");
|
gFields.lnbContext = env->GetFieldID(lnbClazz, "mNativeContext", "J");
|
||||||
gFields.lnbInitID = env->GetMethodID(lnbClazz, "<init>", "(I)V");
|
gFields.lnbInitID = env->GetMethodID(lnbClazz, "<init>", "(I)V");
|
||||||
|
gFields.onLnbEventID = env->GetMethodID(lnbClazz, "onEvent", "(I)V");
|
||||||
|
gFields.onLnbDiseqcMessageID = env->GetMethodID(lnbClazz, "onDiseqcMessage", "([B)V");
|
||||||
|
|
||||||
jclass filterClazz = env->FindClass("android/media/tv/tuner/filter/Filter");
|
jclass filterClazz = env->FindClass("android/media/tv/tuner/filter/Filter");
|
||||||
gFields.filterContext = env->GetFieldID(filterClazz, "mNativeContext", "J");
|
gFields.filterContext = env->GetFieldID(filterClazz, "mNativeContext", "J");
|
||||||
@@ -3204,8 +3234,14 @@ static int android_media_tv_Tuner_lnb_send_diseqc_msg(JNIEnv* env, jobject lnb,
|
|||||||
return (jint) r;
|
return (jint) r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int android_media_tv_Tuner_close_lnb(JNIEnv*, jobject) {
|
static int android_media_tv_Tuner_close_lnb(JNIEnv* env, jobject lnb) {
|
||||||
return 0;
|
sp<Lnb> lnbSp = getLnb(env, lnb);
|
||||||
|
Result r = lnbSp->getILnb()->close();
|
||||||
|
if (r == Result::SUCCESS) {
|
||||||
|
lnbSp->decStrong(lnb);
|
||||||
|
env->SetLongField(lnb, gFields.lnbContext, 0);
|
||||||
|
}
|
||||||
|
return (jint) r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void android_media_tv_Tuner_dvr_set_fd(JNIEnv *env, jobject dvr, jobject jfd) {
|
static void android_media_tv_Tuner_dvr_set_fd(JNIEnv *env, jobject dvr, jobject jfd) {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ struct LnbCallback : public ILnbCallback {
|
|||||||
LnbCallback(jweak tunerObj, LnbId id);
|
LnbCallback(jweak tunerObj, LnbId id);
|
||||||
virtual Return<void> onEvent(LnbEventType lnbEventType);
|
virtual Return<void> onEvent(LnbEventType lnbEventType);
|
||||||
virtual Return<void> onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage);
|
virtual Return<void> onDiseqcMessage(const hidl_vec<uint8_t>& diseqcMessage);
|
||||||
jweak mObject;
|
jweak mLnb;
|
||||||
LnbId mId;
|
LnbId mId;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -199,6 +199,7 @@ private:
|
|||||||
static sp<ITuner> mTuner;
|
static sp<ITuner> mTuner;
|
||||||
hidl_vec<FrontendId> mFeIds;
|
hidl_vec<FrontendId> mFeIds;
|
||||||
sp<IFrontend> mFe;
|
sp<IFrontend> mFe;
|
||||||
|
int mFeId;
|
||||||
hidl_vec<LnbId> mLnbIds;
|
hidl_vec<LnbId> mLnbIds;
|
||||||
sp<ILnb> mLnb;
|
sp<ILnb> mLnb;
|
||||||
sp<IDemux> mDemux;
|
sp<IDemux> mDemux;
|
||||||
|
|||||||
Reference in New Issue
Block a user