Merge "Create Frontend settings classes and implement tune()"
This commit is contained in:
274
media/java/android/media/tv/tuner/FrontendSettings.java
Normal file
274
media/java/android/media/tv/tuner/FrontendSettings.java
Normal file
@@ -0,0 +1,274 @@
|
||||
/*
|
||||
* Copyright 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.media.tv.tuner;
|
||||
|
||||
import android.media.tv.tuner.TunerConstants.FrontendSettingsType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public abstract class FrontendSettings {
|
||||
protected int mFrequency;
|
||||
|
||||
/**
|
||||
* Returns the frontend type.
|
||||
*/
|
||||
@FrontendSettingsType
|
||||
public abstract int getType();
|
||||
|
||||
public int getFrequency() {
|
||||
return mFrequency;
|
||||
}
|
||||
|
||||
// TODO: use hal constants for enum fields
|
||||
// TODO: javaDoc
|
||||
// TODO: add builders and getters for other settings type
|
||||
|
||||
/**
|
||||
* Frontend settings for analog.
|
||||
*/
|
||||
public static class FrontendAnalogSettings extends FrontendSettings {
|
||||
private int mAnalogType;
|
||||
private int mSifStandard;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FRONTEND_TYPE_ANALOG;
|
||||
}
|
||||
|
||||
public int getAnalogType() {
|
||||
return mAnalogType;
|
||||
}
|
||||
|
||||
public int getSifStandard() {
|
||||
return mSifStandard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new builder object.
|
||||
*/
|
||||
public static Builder newBuilder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
private FrontendAnalogSettings(int frequency, int analogType, int sifStandard) {
|
||||
mFrequency = frequency;
|
||||
mAnalogType = analogType;
|
||||
mSifStandard = sifStandard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for FrontendAnalogSettings.
|
||||
*/
|
||||
public static class Builder {
|
||||
private int mFrequency;
|
||||
private int mAnalogType;
|
||||
private int mSifStandard;
|
||||
|
||||
private Builder() {}
|
||||
|
||||
/**
|
||||
* Sets frequency.
|
||||
*/
|
||||
public Builder setFrequency(int frequency) {
|
||||
mFrequency = frequency;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets analog type.
|
||||
*/
|
||||
public Builder setAnalogType(int analogType) {
|
||||
mAnalogType = analogType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets sif standard.
|
||||
*/
|
||||
public Builder setSifStandard(int sifStandard) {
|
||||
mSifStandard = sifStandard;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a FrontendAnalogSettings instance.
|
||||
*/
|
||||
public FrontendAnalogSettings build() {
|
||||
return new FrontendAnalogSettings(mFrequency, mAnalogType, mSifStandard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend settings for ATSC.
|
||||
*/
|
||||
public static class FrontendAtscSettings extends FrontendSettings {
|
||||
public int modulation;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FRONTEND_TYPE_ATSC;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend settings for ATSC-3.
|
||||
*/
|
||||
public static class FrontendAtsc3Settings extends FrontendSettings {
|
||||
public int bandwidth;
|
||||
public byte demodOutputFormat;
|
||||
public List<FrontendAtsc3PlpSettings> plpSettings;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FRONTEND_TYPE_ATSC3;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend settings for DVBS.
|
||||
*/
|
||||
public static class FrontendDvbsSettings extends FrontendSettings {
|
||||
public int modulation;
|
||||
public FrontendDvbsCodeRate coderate;
|
||||
public int symbolRate;
|
||||
public int rolloff;
|
||||
public int pilot;
|
||||
public int inputStreamId;
|
||||
public byte standard;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FRONTEND_TYPE_DVBS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend settings for DVBC.
|
||||
*/
|
||||
public static class FrontendDvbcSettings extends FrontendSettings {
|
||||
public int modulation;
|
||||
public long fec;
|
||||
public int symbolRate;
|
||||
public int outerFec;
|
||||
public byte annex;
|
||||
public int spectralInversion;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FRONTEND_TYPE_DVBC;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend settings for DVBT.
|
||||
*/
|
||||
public static class FrontendDvbtSettings extends FrontendSettings {
|
||||
public int transmissionMode;
|
||||
public int bandwidth;
|
||||
public int constellation;
|
||||
public int hierarchy;
|
||||
public int hpCoderate;
|
||||
public int lpCoderate;
|
||||
public int guardInterval;
|
||||
public boolean isHighPriority;
|
||||
public byte standard;
|
||||
public boolean isMiso;
|
||||
public int plpMode;
|
||||
public byte plpId;
|
||||
public byte plpGroupId;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FRONTEND_TYPE_DVBT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend settings for ISDBS.
|
||||
*/
|
||||
public static class FrontendIsdbsSettings extends FrontendSettings {
|
||||
public int streamId;
|
||||
public int streamIdType;
|
||||
public int modulation;
|
||||
public int coderate;
|
||||
public int symbolRate;
|
||||
public int rolloff;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FRONTEND_TYPE_ISDBS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend settings for ISDBS-3.
|
||||
*/
|
||||
public static class FrontendIsdbs3Settings extends FrontendSettings {
|
||||
public int streamId;
|
||||
public int streamIdType;
|
||||
public int modulation;
|
||||
public int coderate;
|
||||
public int symbolRate;
|
||||
public int rolloff;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FRONTEND_TYPE_ISDBS3;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend settings for ISDBT.
|
||||
*/
|
||||
public static class FrontendIsdbtSettings extends FrontendSettings {
|
||||
public int modulation;
|
||||
public int bandwidth;
|
||||
public int coderate;
|
||||
public int guardInterval;
|
||||
public int serviceAreaId;
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return TunerConstants.FRONTEND_TYPE_ISDBT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PLP settings for ATSC-3.
|
||||
*/
|
||||
public static class FrontendAtsc3PlpSettings {
|
||||
public byte plpId;
|
||||
public int modulation;
|
||||
public int interleaveMode;
|
||||
public int codeRate;
|
||||
public int fec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Code rate for DVBS.
|
||||
*/
|
||||
public static class FrontendDvbsCodeRate {
|
||||
public long fec;
|
||||
public boolean isLinear;
|
||||
public boolean isShortFrames;
|
||||
public int bitsPer1000Symbol;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.media.tv.tuner;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.media.tv.tuner.TunerConstants.DemuxPidType;
|
||||
import android.os.Handler;
|
||||
@@ -78,6 +79,7 @@ public final class Tuner implements AutoCloseable {
|
||||
* Native method to open frontend of the given ID.
|
||||
*/
|
||||
private native Frontend nativeOpenFrontendById(int id);
|
||||
private native int nativeTune(int type, FrontendSettings settings);
|
||||
|
||||
private native Filter nativeOpenFilter(int type, int subType, int bufferSize);
|
||||
|
||||
@@ -207,6 +209,13 @@ public final class Tuner implements AutoCloseable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tunes the frontend to using the settings given.
|
||||
*/
|
||||
public int tune(@NonNull FrontendSettings settings) {
|
||||
return nativeTune(settings.getType(), settings);
|
||||
}
|
||||
|
||||
private List<Integer> getFrontendIds() {
|
||||
mFrontendIds = nativeGetFrontendIds();
|
||||
return mFrontendIds;
|
||||
|
||||
@@ -75,6 +75,21 @@ final class TunerConstants {
|
||||
public static final int DEMUX_T_PID = 1;
|
||||
public static final int DEMUX_MMPT_PID = 2;
|
||||
|
||||
@IntDef({FRONTEND_SETTINGS_ANALOG, FRONTEND_SETTINGS_ATSC, FRONTEND_SETTINGS_ATSC3,
|
||||
FRONTEND_SETTINGS_DVBS, FRONTEND_SETTINGS_DVBC, FRONTEND_SETTINGS_DVBT,
|
||||
FRONTEND_SETTINGS_ISDBS, FRONTEND_SETTINGS_ISDBS3, FRONTEND_SETTINGS_ISDBT})
|
||||
public @interface FrontendSettingsType {}
|
||||
|
||||
public static final int FRONTEND_SETTINGS_ANALOG = 1;
|
||||
public static final int FRONTEND_SETTINGS_ATSC = 2;
|
||||
public static final int FRONTEND_SETTINGS_ATSC3 = 3;
|
||||
public static final int FRONTEND_SETTINGS_DVBS = 4;
|
||||
public static final int FRONTEND_SETTINGS_DVBC = 5;
|
||||
public static final int FRONTEND_SETTINGS_DVBT = 6;
|
||||
public static final int FRONTEND_SETTINGS_ISDBS = 7;
|
||||
public static final int FRONTEND_SETTINGS_ISDBS3 = 8;
|
||||
public static final int FRONTEND_SETTINGS_ISDBT = 9;
|
||||
|
||||
private TunerConstants() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ using ::android::hardware::tv::tuner::V1_0::DemuxFilterMainType;
|
||||
using ::android::hardware::tv::tuner::V1_0::DemuxMmtpPid;
|
||||
using ::android::hardware::tv::tuner::V1_0::DemuxTpid;
|
||||
using ::android::hardware::tv::tuner::V1_0::DemuxTsFilterType;
|
||||
using ::android::hardware::tv::tuner::V1_0::FrontendAnalogSettings;
|
||||
using ::android::hardware::tv::tuner::V1_0::FrontendAnalogSifStandard;
|
||||
using ::android::hardware::tv::tuner::V1_0::FrontendAnalogType;
|
||||
using ::android::hardware::tv::tuner::V1_0::ITuner;
|
||||
using ::android::hardware::tv::tuner::V1_0::Result;
|
||||
|
||||
@@ -263,6 +266,15 @@ jobject JTuner::openLnbById(int id) {
|
||||
id);
|
||||
}
|
||||
|
||||
int JTuner::tune(const FrontendSettings& settings) {
|
||||
if (mFe == NULL) {
|
||||
ALOGE("frontend is not initialized");
|
||||
return (int)Result::INVALID_STATE;
|
||||
}
|
||||
Result result = mFe->tune(settings);
|
||||
return (int)result;
|
||||
}
|
||||
|
||||
bool JTuner::openDemux() {
|
||||
if (mTuner == nullptr) {
|
||||
return false;
|
||||
@@ -417,6 +429,32 @@ static DemuxPid getDemuxPid(int pidType, int pid) {
|
||||
return demuxPid;
|
||||
}
|
||||
|
||||
static FrontendSettings getFrontendSettings(JNIEnv *env, int type, jobject settings) {
|
||||
FrontendSettings frontendSettings;
|
||||
jclass clazz = env->FindClass("android/media/tv/tuner/FrontendSettings");
|
||||
jfieldID freqField = env->GetFieldID(clazz, "frequency", "I");
|
||||
uint32_t freq = static_cast<uint32_t>(env->GetIntField(clazz, freqField));
|
||||
|
||||
// TODO: handle the other 8 types of settings
|
||||
if (type == 1) {
|
||||
// analog
|
||||
clazz = env->FindClass("android/media/tv/tuner/FrontendSettings$FrontendAnalogSettings");
|
||||
FrontendAnalogType analogType =
|
||||
static_cast<FrontendAnalogType>(
|
||||
env->GetIntField(settings, env->GetFieldID(clazz, "mAnalogType", "I")));
|
||||
FrontendAnalogSifStandard sifStandard =
|
||||
static_cast<FrontendAnalogSifStandard>(
|
||||
env->GetIntField(settings, env->GetFieldID(clazz, "mSifStandard", "I")));
|
||||
FrontendAnalogSettings frontendAnalogSettings {
|
||||
.frequency = freq,
|
||||
.type = analogType,
|
||||
.sifStandard = sifStandard,
|
||||
};
|
||||
frontendSettings.analog(frontendAnalogSettings);
|
||||
}
|
||||
return frontendSettings;
|
||||
}
|
||||
|
||||
static sp<IFilter> getFilter(JNIEnv *env, jobject filter) {
|
||||
return (IFilter *)env->GetLongField(filter, gFields.filterContext);
|
||||
}
|
||||
@@ -476,6 +514,11 @@ static jobject android_media_tv_Tuner_open_frontend_by_id(JNIEnv *env, jobject t
|
||||
return tuner->openFrontendById(id);
|
||||
}
|
||||
|
||||
static int android_media_tv_Tuner_tune(JNIEnv *env, jobject thiz, jint type, jobject settings) {
|
||||
sp<JTuner> tuner = getTuner(env, thiz);
|
||||
return tuner->tune(getFrontendSettings(env, type, settings));
|
||||
}
|
||||
|
||||
static jobject android_media_tv_Tuner_get_lnb_ids(JNIEnv *env, jobject thiz) {
|
||||
sp<JTuner> tuner = getTuner(env, thiz);
|
||||
return tuner->getLnbIds();
|
||||
@@ -612,6 +655,8 @@ static const JNINativeMethod gTunerMethods[] = {
|
||||
(void *)android_media_tv_Tuner_get_frontend_ids },
|
||||
{ "nativeOpenFrontendById", "(I)Landroid/media/tv/tuner/Tuner$Frontend;",
|
||||
(void *)android_media_tv_Tuner_open_frontend_by_id },
|
||||
{ "nativeTune", "(ILandroid/media/tv/tuner/FrontendSettings;)I",
|
||||
(void *)android_media_tv_Tuner_tune },
|
||||
{ "nativeOpenFilter", "(III)Landroid/media/tv/tuner/Tuner$Filter;",
|
||||
(void *)android_media_tv_Tuner_open_filter },
|
||||
{ "nativeGetLnbIds", "()Ljava/util/List;",
|
||||
|
||||
@@ -34,6 +34,7 @@ using ::android::hardware::tv::tuner::V1_0::FrontendEventType;
|
||||
using ::android::hardware::tv::tuner::V1_0::FrontendId;
|
||||
using ::android::hardware::tv::tuner::V1_0::FrontendScanMessage;
|
||||
using ::android::hardware::tv::tuner::V1_0::FrontendScanMessageType;
|
||||
using ::android::hardware::tv::tuner::V1_0::FrontendSettings;
|
||||
using ::android::hardware::tv::tuner::V1_0::IDemux;
|
||||
using ::android::hardware::tv::tuner::V1_0::IDescrambler;
|
||||
using ::android::hardware::tv::tuner::V1_0::IDvr;
|
||||
@@ -95,6 +96,7 @@ struct JTuner : public RefBase {
|
||||
sp<ITuner> getTunerService();
|
||||
jobject getFrontendIds();
|
||||
jobject openFrontendById(int id);
|
||||
int tune(const FrontendSettings& settings);
|
||||
jobject getLnbIds();
|
||||
jobject openLnbById(int id);
|
||||
jobject openFilter(DemuxFilterType type, int bufferSize);
|
||||
|
||||
Reference in New Issue
Block a user