Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6848be18 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add Scan to tuner"

parents 3f7ef32b d5b845f5
Loading
Loading
Loading
Loading
+131 −0
Original line number Diff line number Diff line
/*
 * 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.ScanMessageType;

/**
 * Message from frontend during scan operations.
 *
 * @hide
 */
public class ScanMessage {
    private final int mType;
    private final Object mValue;

    private ScanMessage(int type, Object value) {
        mType = type;
        mValue = value;
    }

    /** Gets scan message type. */
    @ScanMessageType
    public int getMessageType() {
        return mType;
    }
    /** Message indicates whether frontend is locked or not. */
    public boolean getIsLocked() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_LOCKED) {
            throw new IllegalStateException();
        }
        return (Boolean) mValue;
    }
    /** Message indicates whether the scan has reached the end or not. */
    public boolean getIsEnd() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_END) {
            throw new IllegalStateException();
        }
        return (Boolean) mValue;
    }
    /** Progress message in percent. */
    public int getProgressPercent() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_PROGRESS_PERCENT) {
            throw new IllegalStateException();
        }
        return (Integer) mValue;
    }
    /** Gets frequency. */
    public int getFrequency() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_FREQUENCY) {
            throw new IllegalStateException();
        }
        return (Integer) mValue;
    }
    /** Gets symbol rate. */
    public int getSymbolRate() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_SYMBOL_RATE) {
            throw new IllegalStateException();
        }
        return (Integer) mValue;
    }
    /** Gets PLP IDs. */
    public int[] getPlpIds() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_PLP_IDS) {
            throw new IllegalStateException();
        }
        return (int[]) mValue;
    }
    /** Gets group IDs. */
    public int[] getGroupIds() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_GROUP_IDS) {
            throw new IllegalStateException();
        }
        return (int[]) mValue;
    }
    /** Gets Input stream IDs. */
    public int[] getInputStreamIds() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_INPUT_STREAM_IDS) {
            throw new IllegalStateException();
        }
        return (int[]) mValue;
    }
    /** Gets the DVB-T or DVB-S standard. */
    public int getStandard() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_STANDARD) {
            throw new IllegalStateException();
        }
        return (int) mValue;
    }

    /** Gets PLP information for ATSC3. */
    public Atsc3PlpInfo[] getAtsc3PlpInfos() {
        if (mType != TunerConstants.SCAN_MESSAGE_TYPE_ATSC3_PLP_INFO) {
            throw new IllegalStateException();
        }
        return (Atsc3PlpInfo[]) mValue;
    }

    /** PLP information for ATSC3. */
    public static class Atsc3PlpInfo {
        private final int mPlpId;
        private final boolean mLlsFlag;

        private Atsc3PlpInfo(int plpId, boolean llsFlag) {
            mPlpId = plpId;
            mLlsFlag = llsFlag;
        }

        /** Gets PLP IDs. */
        public int getPlpId() {
            return mPlpId;
        }
        /** Gets LLS flag. */
        public boolean getLlsFlag() {
            return mLlsFlag;
        }
    }
}
+16 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.content.Context;
import android.media.tv.tuner.TunerConstants.DemuxPidType;
import android.media.tv.tuner.TunerConstants.FilterSubtype;
import android.media.tv.tuner.TunerConstants.FilterType;
import android.media.tv.tuner.TunerConstants.FrontendScanType;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -100,9 +101,9 @@ public final class Tuner implements AutoCloseable {
    private native Frontend nativeOpenFrontendById(int id);
    private native int nativeTune(int type, FrontendSettings settings);
    private native int nativeStopTune();
    private native int nativeScan(int settingsType, FrontendSettings settings, int scanType);
    private native int nativeSetLnb(int lnbId);
    private native int nativeSetLna(boolean enable);

    private native Filter nativeOpenFilter(int type, int subType, int bufferSize);

    private native List<Integer> nativeGetLnbIds();
@@ -123,6 +124,12 @@ public final class Tuner implements AutoCloseable {
         * Invoked when there is a frontend event.
         */
        void onEvent(int frontendEventType);

        /**
         * Invoked when there is a scan message.
         * @param msg
         */
        void onScanMessage(ScanMessage msg);
    }

    /**
@@ -265,6 +272,14 @@ public final class Tuner implements AutoCloseable {
        return nativeStopTune();
    }

    /**
     * Scan channels.
     * @hide
     */
    public int scan(@NonNull FrontendSettings settings, @FrontendScanType int scanType) {
        return nativeScan(settings.getType(), settings, scanType);
    }

    /**
     * Sets Low-Noise Block downconverter (LNB) for satellite frontend.
     *
+45 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ final class TunerConstants {
    public static final int DEMUX_T_PID = 1;
    public static final int DEMUX_MMPT_PID = 2;

    @Retention(RetentionPolicy.SOURCE)
    @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})
@@ -126,6 +127,50 @@ final class TunerConstants {
    public static final int FILTER_SUBTYPE_TLV = 15;
    public static final int FILTER_SUBTYPE_PTP = 16;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({FRONTEND_SCAN_UNDEFINED, FRONTEND_SCAN_AUTO, FRONTEND_SCAN_BLIND})
    public @interface FrontendScanType {}

    public static final int FRONTEND_SCAN_UNDEFINED = Constants.FrontendScanType.SCAN_UNDEFINED;
    public static final int FRONTEND_SCAN_AUTO = Constants.FrontendScanType.SCAN_AUTO;
    public static final int FRONTEND_SCAN_BLIND = Constants.FrontendScanType.SCAN_BLIND;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({SCAN_MESSAGE_TYPE_LOCKED, SCAN_MESSAGE_TYPE_END, SCAN_MESSAGE_TYPE_PROGRESS_PERCENT,
            SCAN_MESSAGE_TYPE_FREQUENCY, SCAN_MESSAGE_TYPE_SYMBOL_RATE, SCAN_MESSAGE_TYPE_PLP_IDS,
            SCAN_MESSAGE_TYPE_GROUP_IDS, SCAN_MESSAGE_TYPE_INPUT_STREAM_IDS,
            SCAN_MESSAGE_TYPE_STANDARD, SCAN_MESSAGE_TYPE_ATSC3_PLP_INFO})
    public @interface ScanMessageType {}

    public static final int SCAN_MESSAGE_TYPE_LOCKED = Constants.FrontendScanMessageType.LOCKED;
    public static final int SCAN_MESSAGE_TYPE_END = Constants.FrontendScanMessageType.END;
    public static final int SCAN_MESSAGE_TYPE_PROGRESS_PERCENT =
            Constants.FrontendScanMessageType.PROGRESS_PERCENT;
    public static final int SCAN_MESSAGE_TYPE_FREQUENCY =
            Constants.FrontendScanMessageType.FREQUENCY;
    public static final int SCAN_MESSAGE_TYPE_SYMBOL_RATE =
            Constants.FrontendScanMessageType.SYMBOL_RATE;
    public static final int SCAN_MESSAGE_TYPE_PLP_IDS = Constants.FrontendScanMessageType.PLP_IDS;
    public static final int SCAN_MESSAGE_TYPE_GROUP_IDS =
            Constants.FrontendScanMessageType.GROUP_IDS;
    public static final int SCAN_MESSAGE_TYPE_INPUT_STREAM_IDS =
            Constants.FrontendScanMessageType.INPUT_STREAM_IDS;
    public static final int SCAN_MESSAGE_TYPE_STANDARD =
            Constants.FrontendScanMessageType.STANDARD;
    public static final int SCAN_MESSAGE_TYPE_ATSC3_PLP_INFO =
            Constants.FrontendScanMessageType.ATSC3_PLP_INFO;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({FILTER_SETTINGS_TS, FILTER_SETTINGS_MMTP, FILTER_SETTINGS_IP, FILTER_SETTINGS_TLV,
            FILTER_SETTINGS_ALP})
    public @interface FilterSettingsType {}

    public static final int FILTER_SETTINGS_TS = Constants.DemuxFilterMainType.TS;
    public static final int FILTER_SETTINGS_MMTP = Constants.DemuxFilterMainType.MMTP;
    public static final int FILTER_SETTINGS_IP = Constants.DemuxFilterMainType.IP;
    public static final int FILTER_SETTINGS_TLV = Constants.DemuxFilterMainType.TLV;
    public static final int FILTER_SETTINGS_ALP = Constants.DemuxFilterMainType.ALP;

    @Retention(RetentionPolicy.SOURCE)
    @IntDef({DVR_SETTINGS_RECORD, DVR_SETTINGS_PLAYBACK})
    public @interface DvrSettingsType {}
+18 −0
Original line number Diff line number Diff line
@@ -312,6 +312,15 @@ int JTuner::tune(const FrontendSettings& settings) {
    return (int)result;
}

int JTuner::scan(const FrontendSettings& settings, FrontendScanType scanType) {
    if (mFe == NULL) {
        ALOGE("frontend is not initialized");
        return (int)Result::INVALID_STATE;
    }
    Result result = mFe->scan(settings, scanType);
    return (int)result;
}

bool JTuner::openDemux() {
    if (mTuner == nullptr) {
        return false;
@@ -604,6 +613,13 @@ static int android_media_tv_Tuner_stop_tune(JNIEnv, jobject) {
    return 0;
}

static int android_media_tv_Tuner_scan(
        JNIEnv *env, jobject thiz, jint settingsType, jobject settings, jint scanType) {
    sp<JTuner> tuner = getTuner(env, thiz);
    return tuner->scan(getFrontendSettings(
            env, settingsType, settings), static_cast<FrontendScanType>(scanType));
}

static int android_media_tv_Tuner_set_lnb(JNIEnv, jobject, jint) {
    return 0;
}
@@ -863,6 +879,8 @@ static const JNINativeMethod gTunerMethods[] = {
    { "nativeTune", "(ILandroid/media/tv/tuner/FrontendSettings;)I",
            (void *)android_media_tv_Tuner_tune },
    { "nativeStopTune", "()I", (void *)android_media_tv_Tuner_stop_tune },
    { "nativeScan", "(ILandroid/media/tv/tuner/FrontendSettings;I)I",
            (void *)android_media_tv_Tuner_scan },
    { "nativeSetLnb", "(I)I", (void *)android_media_tv_Tuner_set_lnb },
    { "nativeSetLna", "(Z)I", (void *)android_media_tv_Tuner_set_lna },
    { "nativeOpenFilter", "(III)Landroid/media/tv/tuner/Tuner$Filter;",
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,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::FrontendScanType;
using ::android::hardware::tv::tuner::V1_0::FrontendSettings;
using ::android::hardware::tv::tuner::V1_0::IDemux;
using ::android::hardware::tv::tuner::V1_0::IDescrambler;
@@ -122,6 +123,7 @@ struct JTuner : public RefBase {
    jobject getFrontendIds();
    jobject openFrontendById(int id);
    int tune(const FrontendSettings& settings);
    int scan(const FrontendSettings& settings, FrontendScanType scanType);
    jobject getLnbIds();
    jobject openLnbById(int id);
    jobject openFilter(DemuxFilterType type, int bufferSize);