diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-05 07:30:20 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-05 07:30:20 +0000 |
commit | bb2e798ef4d546dd54cd9e95796403062b860c15 (patch) | |
tree | d31e2adc1f9cce4f27ca07d30bee921032e33a3c /src/com/android/tv/tuner/TunerHal.java | |
parent | bc7f430decab0bc34a533811efe457d4615f28aa (diff) | |
parent | 6ebde20b03db4c0d57f67acaac11832b610b966b (diff) | |
download | TV-bb2e798ef4d546dd54cd9e95796403062b860c15.tar.gz |
Snap for 4378450 from 6ebde20b03db4c0d57f67acaac11832b610b966b to oc-mr1-releaseandroid-wear-8.1.0_r1android-vts-8.1_r9android-vts-8.1_r8android-vts-8.1_r7android-vts-8.1_r6android-vts-8.1_r5android-vts-8.1_r4android-vts-8.1_r3android-vts-8.1_r14android-vts-8.1_r13android-vts-8.1_r12android-vts-8.1_r11android-vts-8.1_r10android-security-8.1.0_r93android-security-8.1.0_r92android-security-8.1.0_r91android-security-8.1.0_r90android-security-8.1.0_r89android-security-8.1.0_r88android-security-8.1.0_r87android-security-8.1.0_r86android-security-8.1.0_r85android-security-8.1.0_r84android-security-8.1.0_r83android-security-8.1.0_r82android-cts-8.1_r9android-cts-8.1_r8android-cts-8.1_r7android-cts-8.1_r6android-cts-8.1_r5android-cts-8.1_r4android-cts-8.1_r3android-cts-8.1_r25android-cts-8.1_r24android-cts-8.1_r23android-cts-8.1_r22android-cts-8.1_r21android-cts-8.1_r20android-cts-8.1_r2android-cts-8.1_r19android-cts-8.1_r18android-cts-8.1_r17android-cts-8.1_r16android-cts-8.1_r15android-cts-8.1_r14android-cts-8.1_r13android-cts-8.1_r12android-cts-8.1_r11android-cts-8.1_r10android-cts-8.1_r1android-8.1.0_r81android-8.1.0_r80android-8.1.0_r79android-8.1.0_r78android-8.1.0_r77android-8.1.0_r76android-8.1.0_r75android-8.1.0_r74android-8.1.0_r73android-8.1.0_r72android-8.1.0_r71android-8.1.0_r70android-8.1.0_r69android-8.1.0_r68android-8.1.0_r66android-8.1.0_r6android-8.1.0_r5android-8.1.0_r4android-8.1.0_r3android-8.1.0_r23android-8.1.0_r19android-8.1.0_r16android-8.1.0_r15android-8.1.0_r12android-8.1.0_r11android-8.1.0_r10android-8.1.0_r1security-oc-mr1-releaseoreo-mr1-wear-releaseoreo-mr1-vts-releaseoreo-mr1-security-releaseoreo-mr1-s1-releaseoreo-mr1-releaseoreo-mr1-cuttlefish-testingoreo-mr1-cts-releaseoreo-m4-s1-release
Change-Id: I07f19344c030a9c2b0fd7ba425f7bf7462575f92
Diffstat (limited to 'src/com/android/tv/tuner/TunerHal.java')
-rw-r--r-- | src/com/android/tv/tuner/TunerHal.java | 129 |
1 files changed, 111 insertions, 18 deletions
diff --git a/src/com/android/tv/tuner/TunerHal.java b/src/com/android/tv/tuner/TunerHal.java index de19766e..1176cdf0 100644 --- a/src/com/android/tv/tuner/TunerHal.java +++ b/src/com/android/tv/tuner/TunerHal.java @@ -19,7 +19,12 @@ package com.android.tv.tuner; import android.content.Context; import android.support.annotation.IntDef; import android.support.annotation.StringDef; +import android.support.annotation.WorkerThread; import android.util.Log; +import android.util.Pair; + +import com.android.tv.Features; +import com.android.tv.customization.TvCustomizationManager; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -46,14 +51,43 @@ public abstract class TunerHal implements AutoCloseable { public static final String MODULATION_8VSB = "8VSB"; public static final String MODULATION_QAM256 = "QAM256"; + @IntDef({ DELIVERY_SYSTEM_UNDEFINED, DELIVERY_SYSTEM_ATSC, DELIVERY_SYSTEM_DVBC, + DELIVERY_SYSTEM_DVBS, DELIVERY_SYSTEM_DVBS2, DELIVERY_SYSTEM_DVBT, + DELIVERY_SYSTEM_DVBT2 }) + @Retention(RetentionPolicy.SOURCE) + public @interface DeliverySystemType {} + public static final int DELIVERY_SYSTEM_UNDEFINED = 0; + public static final int DELIVERY_SYSTEM_ATSC = 1; + public static final int DELIVERY_SYSTEM_DVBC = 2; + public static final int DELIVERY_SYSTEM_DVBS = 3; + public static final int DELIVERY_SYSTEM_DVBS2 = 4; + public static final int DELIVERY_SYSTEM_DVBT = 5; + public static final int DELIVERY_SYSTEM_DVBT2 = 6; + + @IntDef({ TUNER_TYPE_BUILT_IN, TUNER_TYPE_USB, TUNER_TYPE_NETWORK }) + @Retention(RetentionPolicy.SOURCE) + public @interface TunerType {} public static final int TUNER_TYPE_BUILT_IN = 1; public static final int TUNER_TYPE_USB = 2; + public static final int TUNER_TYPE_NETWORK = 3; protected static final int PID_PAT = 0; protected static final int PID_ATSC_SI_BASE = 0x1ffb; + protected static final int PID_DVB_SDT = 0x0011; + protected static final int PID_DVB_EIT = 0x0012; protected static final int DEFAULT_VSB_TUNE_TIMEOUT_MS = 2000; protected static final int DEFAULT_QAM_TUNE_TIMEOUT_MS = 4000; // Some device takes time for // QAM256 tuning. + @IntDef({ + BUILT_IN_TUNER_TYPE_LINUX_DVB + }) + @Retention(RetentionPolicy.SOURCE) + private @interface BuiltInTunerType {} + private static final int BUILT_IN_TUNER_TYPE_LINUX_DVB = 1; + + private static Integer sBuiltInTunerType; + + protected @DeliverySystemType int mDeliverySystemType; private boolean mIsStreaming; private int mFrequency; private String mModulation; @@ -67,33 +101,62 @@ public abstract class TunerHal implements AutoCloseable { * @param context context for creating the TunerHal instance * @return the TunerHal instance */ + @WorkerThread public synchronized static TunerHal createInstance(Context context) { TunerHal tunerHal = null; - if (getTunerType(context) == TUNER_TYPE_BUILT_IN) { - } - if (tunerHal == null) { - tunerHal = new UsbTunerHal(context); - } - if (tunerHal.openFirstAvailable()) { - return tunerHal; + if (DvbTunerHal.getNumberOfDevices(context) > 0) { + if (DEBUG) Log.d(TAG, "Use DvbTunerHal"); + tunerHal = new DvbTunerHal(context); } - return null; + return tunerHal != null && tunerHal.openFirstAvailable() ? tunerHal : null; } /** * Gets the number of tuner devices currently present. */ - public static int getTunerCount(Context context) { - if (getTunerType(context) == TUNER_TYPE_BUILT_IN) { + @WorkerThread + public static Pair<Integer, Integer> getTunerTypeAndCount(Context context) { + if (useBuiltInTuner(context)) { + if (getBuiltInTunerType(context) == BUILT_IN_TUNER_TYPE_LINUX_DVB) { + return new Pair<>(TUNER_TYPE_BUILT_IN, DvbTunerHal.getNumberOfDevices(context)); + } + } else { + int usbTunerCount = DvbTunerHal.getNumberOfDevices(context); + if (usbTunerCount > 0) { + return new Pair<>(TUNER_TYPE_USB, usbTunerCount); + } } - return UsbTunerHal.getNumberOfDevices(context); + return new Pair<>(null, 0); + } + + /** + * Check a delivery system is for DVB or not. + */ + public static boolean isDvbDeliverySystem(@DeliverySystemType int deliverySystemType) { + return deliverySystemType == DELIVERY_SYSTEM_DVBC + || deliverySystemType == DELIVERY_SYSTEM_DVBS + || deliverySystemType == DELIVERY_SYSTEM_DVBS2 + || deliverySystemType == DELIVERY_SYSTEM_DVBT + || deliverySystemType == DELIVERY_SYSTEM_DVBT2; } /** - * Gets the type of tuner devices currently used. + * Returns if tuner input service would use built-in tuners instead of USB tuners or network + * tuners. */ - public static int getTunerType(Context context) { - return TUNER_TYPE_USB; + static boolean useBuiltInTuner(Context context) { + return getBuiltInTunerType(context) != 0; + } + + private static @BuiltInTunerType int getBuiltInTunerType(Context context) { + if (sBuiltInTunerType == null) { + sBuiltInTunerType = 0; + if (TvCustomizationManager.hasLinuxDvbBuiltInTuner(context) + && DvbTunerHal.getNumberOfDevices(context) > 0) { + sBuiltInTunerType = BUILT_IN_TUNER_TYPE_LINUX_DVB; + } + } + return sBuiltInTunerType; } protected TunerHal(Context context) { @@ -106,6 +169,20 @@ public abstract class TunerHal implements AutoCloseable { return mIsStreaming; } + protected void getDeliverySystemTypeFromDevice() { + if (mDeliverySystemType == DELIVERY_SYSTEM_UNDEFINED) { + mDeliverySystemType = nativeGetDeliverySystemType(getDeviceId()); + } + } + + /** + * Returns {@code true} if this tuner HAL can be reused to save tuning time between channels + * of the same frequency. + */ + public boolean isReusable() { + return true; + } + @Override protected void finalize() throws Throwable { super.finalize(); @@ -131,9 +208,12 @@ public abstract class TunerHal implements AutoCloseable { * * @param frequency a frequency of the channel to tune to * @param modulation a modulation method of the channel to tune to + * @param channelNumber channel number when channel number is already known. Some tuner HAL + * may use channelNumber instead of frequency for tune. * @return {@code true} if the operation was successful, {@code false} otherwise */ - public synchronized boolean tune(int frequency, @ModulationType String modulation) { + public synchronized boolean tune(int frequency, @ModulationType String modulation, + String channelNumber) { if (!isDeviceOpen()) { Log.e(TAG, "There's no available device"); return false; @@ -148,6 +228,10 @@ public abstract class TunerHal implements AutoCloseable { if (mFrequency == frequency && Objects.equals(mModulation, modulation)) { addPidFilter(PID_PAT, FILTER_TYPE_OTHER); addPidFilter(PID_ATSC_SI_BASE, FILTER_TYPE_OTHER); + if (isDvbDeliverySystem(mDeliverySystemType)) { + addPidFilter(PID_DVB_SDT, FILTER_TYPE_OTHER); + addPidFilter(PID_DVB_EIT, FILTER_TYPE_OTHER); + } mIsStreaming = true; return true; } @@ -156,6 +240,10 @@ public abstract class TunerHal implements AutoCloseable { if (nativeTune(getDeviceId(), frequency, modulation, timeout_ms)) { addPidFilter(PID_PAT, FILTER_TYPE_OTHER); addPidFilter(PID_ATSC_SI_BASE, FILTER_TYPE_OTHER); + if (isDvbDeliverySystem(mDeliverySystemType)) { + addPidFilter(PID_DVB_SDT, FILTER_TYPE_OTHER); + addPidFilter(PID_DVB_EIT, FILTER_TYPE_OTHER); + } mFrequency = frequency; mModulation = modulation; mIsStreaming = true; @@ -189,6 +277,7 @@ public abstract class TunerHal implements AutoCloseable { protected native void nativeAddPidFilter(long deviceId, int pid, @FilterType int filterType); protected native void nativeCloseAllPidFilters(long deviceId); protected native void nativeSetHasPendingTune(long deviceId, boolean hasPendingTune); + protected native int nativeGetDeliverySystemType(long deviceId); /** * Stops current tuning. The tuner device and pid filters will be reset by this call and make @@ -210,6 +299,10 @@ public abstract class TunerHal implements AutoCloseable { nativeSetHasPendingTune(getDeviceId(), hasPendingTune); } + public int getDeliverySystemType() { + return mDeliverySystemType; + } + protected native void nativeStopTune(long deviceId); /** @@ -235,7 +328,7 @@ public abstract class TunerHal implements AutoCloseable { /** * Opens Linux DVB frontend device. This method is called from native JNI and used only for - * UsbTunerHal. + * DvbTunerHal. */ protected int openDvbFrontEndFd() { return -1; @@ -243,7 +336,7 @@ public abstract class TunerHal implements AutoCloseable { /** * Opens Linux DVB demux device. This method is called from native JNI and used only for - * UsbTunerHal. + * DvbTunerHal. */ protected int openDvbDemuxFd() { return -1; @@ -251,7 +344,7 @@ public abstract class TunerHal implements AutoCloseable { /** * Opens Linux DVB dvr device. This method is called from native JNI and used only for - * UsbTunerHal. + * DvbTunerHal. */ protected int openDvbDvrFd() { return -1; |