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

Commit 4a11c440 authored by Amy Zhang's avatar Amy Zhang Committed by Android (Google) Code Review
Browse files

Merge changes from topic "filterid"

* changes:
  Add TunerVersionChecker  to expose the Tuner HAL implementation version
  Make Tuner java framework and Tuner JNI adopt Tuner HAL 1.1
parents 37f1f0e9 7b3b578d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -482,6 +482,7 @@ java_library {
        "android.hardware.thermal-V2.0-java",
        "android.hardware.tv.input-V1.0-java-constants",
        "android.hardware.tv.tuner-V1.0-java-constants",
        "android.hardware.tv.tuner-V1.1-java-constants",
        "android.hardware.usb-V1.0-java-constants",
        "android.hardware.usb-V1.1-java-constants",
        "android.hardware.usb-V1.2-java-constants",
+13 −0
Original line number Diff line number Diff line
@@ -5052,6 +5052,8 @@ package android.media.tv.tuner {
    method public void updateResourcePriority(int, int);
    field public static final int INVALID_AV_SYNC_ID = -1; // 0xffffffff
    field public static final int INVALID_FILTER_ID = -1; // 0xffffffff
    field public static final long INVALID_FILTER_ID_64BIT = -1L; // 0xffffffffffffffffL
    field public static final int INVALID_MMTP_RECORD_EVENT_MPT_SEQUENCE_NUM = -1; // 0xffffffff
    field public static final int INVALID_STREAM_ID = 65535; // 0xffff
    field public static final long INVALID_TIMESTAMP = -1L; // 0xffffffffffffffffL
    field public static final int INVALID_TS_PID = 65535; // 0xffff
@@ -5071,6 +5073,13 @@ package android.media.tv.tuner {
    method public void onResourceLost(@NonNull android.media.tv.tuner.Tuner);
  }
  public final class TunerVersionChecker {
    method public static int getTunerVersion();
    field public static final int TUNER_VERSION_1_0 = 65536; // 0x10000
    field public static final int TUNER_VERSION_1_1 = 65537; // 0x10001
    field public static final int TUNER_VERSION_UNKNOWN = 0; // 0x0
  }
}
package android.media.tv.tuner.dvr {
@@ -5204,6 +5213,7 @@ package android.media.tv.tuner.filter {
    method public int configure(@NonNull android.media.tv.tuner.filter.FilterConfiguration);
    method public int flush();
    method public int getId();
    method public long getId64Bit();
    method public int read(@NonNull byte[], long, long);
    method public int setDataSource(@Nullable android.media.tv.tuner.filter.Filter);
    method public int start();
@@ -5304,6 +5314,8 @@ package android.media.tv.tuner.filter {
  public class MmtpRecordEvent extends android.media.tv.tuner.filter.FilterEvent {
    method public long getDataLength();
    method public int getMpuSequenceNumber();
    method public long getPts();
    method public int getScHevcIndexMask();
  }
@@ -5466,6 +5478,7 @@ package android.media.tv.tuner.filter {
  public class TsRecordEvent extends android.media.tv.tuner.filter.FilterEvent {
    method public long getDataLength();
    method public int getPacketId();
    method public long getPts();
    method public int getScIndexMask();
    method public int getTsIndexMask();
  }
+15 −0
Original line number Diff line number Diff line
@@ -2130,6 +2130,21 @@ package android.media.tv {

}

package android.media.tv.tuner {

  public final class TunerVersionChecker {
    method public static int getMajorVersion(int);
    method public static int getMinorVersion(int);
    method public static int getTunerVersion();
    method public static boolean isHigherOrEqualVersionTo(int);
    method public static boolean supportTunerVersion(int);
    field public static final int TUNER_VERSION_1_0 = 65536; // 0x10000
    field public static final int TUNER_VERSION_1_1 = 65537; // 0x10001
    field public static final int TUNER_VERSION_UNKNOWN = 0; // 0x0
  }

}

package android.metrics {

  public class LogMaker {
+42 −4
Original line number Diff line number Diff line
@@ -98,15 +98,34 @@ public class Tuner implements AutoCloseable {
     * Invalid timestamp.
     *
     * <p>Returned by {@link android.media.tv.tuner.filter.TimeFilter#getSourceTime()},
     * {@link android.media.tv.tuner.filter.TimeFilter#getTimeStamp()}, or
     * {@link Tuner#getAvSyncTime(int)} when the requested timestamp is not available.
     * {@link android.media.tv.tuner.filter.TimeFilter#getTimeStamp()},
     * {@link Tuner#getAvSyncTime(int)} or {@link TsRecordEvent#getPts()} and
     * {@link MmtpRecordEvent#getPts()} when the requested timestamp is not available.
     *
     * @see android.media.tv.tuner.filter.TimeFilter#getSourceTime()
     * @see android.media.tv.tuner.filter.TimeFilter#getTimeStamp()
     * @see Tuner#getAvSyncTime(int)
     * @see android.media.tv.tuner.filter.TsRecordEvent#getPts()
     * @see android.media.tv.tuner.filter.MmtpRecordEvent#getPts()
     */
    public static final long INVALID_TIMESTAMP = -1L;

    public static final long INVALID_TIMESTAMP =
            android.hardware.tv.tuner.V1_1.Constants.Constant64Bit.INVALID_PRESENTATION_TIME_STAMP;
    /**
     * Invalid mpu sequence number in MmtpRecordEvent.
     *
     * <p>Returned by {@link MmtpRecordEvent#getMpuSequenceNumber()} when the requested sequence
     * number is not available.
     *
     * @see android.media.tv.tuner.filter.MmtpRecordEvent#getMpuSequenceNumber()
     */
    public static final int INVALID_MMTP_RECORD_EVENT_MPT_SEQUENCE_NUM =
            android.hardware.tv.tuner.V1_1.Constants.Constant
                    .INVALID_MMTP_RECORD_EVENT_MPT_SEQUENCE_NUM;
    /**
     * Invalid 64-bit filter ID.
     */
    public static final long INVALID_FILTER_ID_64BIT =
            android.hardware.tv.tuner.V1_1.Constants.Constant64Bit.INVALID_FILTER_ID_64BIT;

    /** @hide */
    @IntDef(prefix = "SCAN_TYPE_", value = {SCAN_TYPE_UNDEFINED, SCAN_TYPE_AUTO, SCAN_TYPE_BLIND})
@@ -204,6 +223,7 @@ public class Tuner implements AutoCloseable {
    private final Context mContext;
    private final TunerResourceManager mTunerResourceManager;
    private final int mClientId;
    private static int sTunerVersion = TunerVersionChecker.TUNER_VERSION_UNKNOWN;

    private Frontend mFrontend;
    private EventHandler mHandler;
@@ -255,6 +275,14 @@ public class Tuner implements AutoCloseable {
    public Tuner(@NonNull Context context, @Nullable String tvInputSessionId,
            @TvInputService.PriorityHintUseCaseType int useCase) {
        nativeSetup();
        sTunerVersion = nativeGetTunerVersion();
        if (sTunerVersion == TunerVersionChecker.TUNER_VERSION_UNKNOWN) {
            Log.e(TAG, "Unknown Tuner version!");
        } else {
            Log.d(TAG, "Current Tuner version is "
                    + TunerVersionChecker.getMajorVersion(sTunerVersion) + "."
                    + TunerVersionChecker.getMinorVersion(sTunerVersion) + ".");
        }
        mContext = context;
        mTunerResourceManager = (TunerResourceManager)
                context.getSystemService(Context.TV_TUNER_RESOURCE_MGR_SERVICE);
@@ -294,6 +322,11 @@ public class Tuner implements AutoCloseable {
        mTunerResourceManager.setFrontendInfoList(infos);
    }

    /** @hide */
    public static int getTunerVersion() {
        return sTunerVersion;
    }

    /** @hide */
    public List<Integer> getFrontendIds() {
        return nativeGetFrontendIds();
@@ -416,6 +449,11 @@ public class Tuner implements AutoCloseable {
     */
    private native void nativeSetup();

    /**
     * Native method to get all frontend IDs.
     */
    private native int nativeGetTunerVersion();

    /**
     * Native method to get all frontend IDs.
     */
+153 −0
Original line number Diff line number Diff line
/*
 * Copyright 2020 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.annotation.IntDef;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.util.Log;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Utility class to check the currently running Tuner Hal implementation version.
 *
 * APIs that are not supported by the HAL implementation version would be no-op.
 *
 * @hide
 */
@TestApi
@SystemApi
public final class TunerVersionChecker {
    private static final String TAG = "TunerVersionChecker";

    private TunerVersionChecker() {}

    /** @hide */
    @IntDef(prefix = "TUNER_VERSION_", value = {TUNER_VERSION_UNKNOWN, TUNER_VERSION_1_0,
                                                TUNER_VERSION_1_1})
    @Retention(RetentionPolicy.SOURCE)
    public @interface TunerVersion {}
    /**
     * Unknown Tuner version.
     */
    public static final int TUNER_VERSION_UNKNOWN = 0;
    /**
     * Tuner version 1.0.
     */
    public static final int TUNER_VERSION_1_0 = (1 << 16);
    /**
     * Tuner version 1.1.
     */
    public static final int TUNER_VERSION_1_1 = ((1 << 16) | 1);

    /**
     * Get the current running Tuner version.
     *
     * @return Tuner version.
     */
    @TunerVersion
    public static int getTunerVersion() {
        return Tuner.getTunerVersion();
    }

    /**
     * Check if the current running Tuner version supports the given version.
     *
     * <p>Note that we treat different major versions as unsupported among each other. If any
     * feature could be supported across major versions, please use
     * {@link #isHigherOrEqualVersionTo(int)} to check.
     *
     * @param version the version to support.
     *
     * @return true if the current version is under the same major version as the given version
     * and has higher or the same minor version as the given version.
     * @hide
     */
    @TestApi
    public static boolean supportTunerVersion(@TunerVersion int version) {
        int currentVersion = Tuner.getTunerVersion();
        return isHigherOrEqualVersionTo(version)
                && (getMajorVersion(version) == getMajorVersion(currentVersion));
    }

    /**
     * Check if the current running Tuner version is higher than or equal to a given version.
     *
     * @param version the version to compare.
     *
     * @return true if the current version is higher or equal to the support version.
     * @hide
     */
    @TestApi
    public static boolean isHigherOrEqualVersionTo(@TunerVersion int version) {
        int currentVersion = Tuner.getTunerVersion();
        return currentVersion >= version;
    }

    /**
     * Get the major version from a version number.
     *
     * @param version the version to be checked.
     *
     * @return the major version number.
     * @hide
     */
    @TestApi
    public static int getMajorVersion(@TunerVersion int version) {
        return ((version & 0xFFFF0000) >>> 16);
    }

    /**
     * Get the major version from a version number.
     *
     * @param version the version to be checked.
     *
     * @return the minor version number.
     * @hide
     */
    @TestApi
    public static int getMinorVersion(@TunerVersion int version) {
        return (version & 0xFFFF);
    }

    /** @hide */
    public static boolean checkHigherOrEqualVersionTo(
            @TunerVersion int version, String methodName) {
        if (!TunerVersionChecker.isHigherOrEqualVersionTo(version)) {
            Log.e(TAG, "Current Tuner version "
                    + TunerVersionChecker.getMajorVersion(Tuner.getTunerVersion()) + "."
                    + TunerVersionChecker.getMinorVersion(Tuner.getTunerVersion())
                    + " does not support " + methodName + ".");
            return false;
        }
        return true;
    }

    /** @hide */
    public static boolean checkSupportVersion(@TunerVersion int version, String methodName) {
        if (!TunerVersionChecker.supportTunerVersion(version)) {
            Log.e(TAG, "Current Tuner version "
                    + TunerVersionChecker.getMajorVersion(Tuner.getTunerVersion()) + "."
                    + TunerVersionChecker.getMinorVersion(Tuner.getTunerVersion())
                    + " does not support " + methodName + ".");
            return false;
        }
        return true;
    }
}
Loading