From 54c79100d3dee330f02da4162380aed7d834fa8c Mon Sep 17 00:00:00 2001 From: Hongguang Date: Mon, 1 Nov 2021 19:06:58 -0700 Subject: [PATCH] Add some new features to tuner. *) Allow section filter version to be optional. *) Add separate DemuxScAvcIndex for the AVC. *) Support for secure MediaFilter buffer configuration. Bug: 191825295 Bug: 204807405 Bug: 204178547 Test: atest VtsHalTvTunerTargetTest Test: atest android.media.tv.tuner.cts on HIDL and AIDL HALs Change-Id: I060df19778a862ceef6a6f7ae96f8e2177998dea --- core/api/system-current.txt | 4 ++ .../media/tv/tuner/filter/AvSettings.java | 46 +++++++++++++++++-- .../media/tv/tuner/filter/RecordSettings.java | 18 +++++--- .../filter/SectionSettingsWithTableInfo.java | 9 +++- media/jni/android_media_tv_Tuner.cpp | 19 +++++++- 5 files changed, 81 insertions(+), 15 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 9ade639dc9a59..f0cbee3632b97 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -6305,6 +6305,7 @@ package android.media.tv.tuner.filter { method public int getAudioStreamType(); method public int getVideoStreamType(); method public boolean isPassthrough(); + method public boolean useSecureMemory(); field public static final int AUDIO_STREAM_TYPE_AAC = 6; // 0x6 field public static final int AUDIO_STREAM_TYPE_AC3 = 7; // 0x7 field public static final int AUDIO_STREAM_TYPE_AC4 = 9; // 0x9 @@ -6340,6 +6341,7 @@ package android.media.tv.tuner.filter { method @NonNull public android.media.tv.tuner.filter.AvSettings build(); method @NonNull public android.media.tv.tuner.filter.AvSettings.Builder setAudioStreamType(int); method @NonNull public android.media.tv.tuner.filter.AvSettings.Builder setPassthrough(boolean); + method @NonNull public android.media.tv.tuner.filter.AvSettings.Builder setUseSecureMemory(boolean); method @NonNull public android.media.tv.tuner.filter.AvSettings.Builder setVideoStreamType(int); } @@ -6515,6 +6517,7 @@ package android.media.tv.tuner.filter { method public int getTsIndexMask(); field public static final int INDEX_TYPE_NONE = 0; // 0x0 field public static final int INDEX_TYPE_SC = 1; // 0x1 + field public static final int INDEX_TYPE_SC_AVC = 3; // 0x3 field public static final int INDEX_TYPE_SC_HEVC = 2; // 0x2 field public static final int MPT_INDEX_AUDIO = 262144; // 0x40000 field public static final int MPT_INDEX_MPT = 65536; // 0x10000 @@ -6607,6 +6610,7 @@ package android.media.tv.tuner.filter { method @NonNull public static android.media.tv.tuner.filter.SectionSettingsWithTableInfo.Builder builder(int); method public int getTableId(); method public int getVersion(); + field public static final int INVALID_TABLE_INFO_VERSION = -1; // 0xffffffff } public static class SectionSettingsWithTableInfo.Builder extends android.media.tv.tuner.filter.SectionSettings.Builder { diff --git a/media/java/android/media/tv/tuner/filter/AvSettings.java b/media/java/android/media/tv/tuner/filter/AvSettings.java index 8bcf3d268c3f1..ed04754365041 100644 --- a/media/java/android/media/tv/tuner/filter/AvSettings.java +++ b/media/java/android/media/tv/tuner/filter/AvSettings.java @@ -186,9 +186,10 @@ public class AvSettings extends Settings { private final boolean mIsPassthrough; private int mAudioStreamType = AUDIO_STREAM_TYPE_UNDEFINED; private int mVideoStreamType = VIDEO_STREAM_TYPE_UNDEFINED; + private final boolean mUseSecureMemory; - private AvSettings(int mainType, boolean isAudio, boolean isPassthrough, - int audioStreamType, int videoStreamType) { + private AvSettings(int mainType, boolean isAudio, boolean isPassthrough, int audioStreamType, + int videoStreamType, boolean useSecureMemory) { super(TunerUtils.getFilterSubtype( mainType, isAudio @@ -197,6 +198,7 @@ public class AvSettings extends Settings { mIsPassthrough = isPassthrough; mAudioStreamType = audioStreamType; mVideoStreamType = videoStreamType; + mUseSecureMemory = useSecureMemory; } /** @@ -222,6 +224,16 @@ public class AvSettings extends Settings { return mVideoStreamType; } + /** + * Checks whether secure memory is used. + * + *

This query is only supported by Tuner HAL 2.0 or higher. The return value on HAL 1.1 and + * lower is undefined. Use {@link TunerVersionChecker#getTunerVersion()} to check the version. + */ + public boolean useSecureMemory() { + return mUseSecureMemory; + } + /** * Creates a builder for {@link AvSettings}. * @@ -239,9 +251,10 @@ public class AvSettings extends Settings { public static class Builder { private final int mMainType; private final boolean mIsAudio; - private boolean mIsPassthrough; + private boolean mIsPassthrough = false; private int mAudioStreamType = AUDIO_STREAM_TYPE_UNDEFINED; private int mVideoStreamType = VIDEO_STREAM_TYPE_UNDEFINED; + boolean mUseSecureMemory = false; private Builder(int mainType, boolean isAudio) { mMainType = mainType; @@ -250,6 +263,8 @@ public class AvSettings extends Settings { /** * Sets whether it's passthrough. + * + *

Default value is {@code false}. */ @NonNull public Builder setPassthrough(boolean isPassthrough) { @@ -263,6 +278,8 @@ public class AvSettings extends Settings { *

This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version. * + *

Default is {@link #AUDIO_STREAM_TYPE_UNDEFINED}. + * * @param audioStreamType the audio stream type to set. */ @NonNull @@ -281,6 +298,8 @@ public class AvSettings extends Settings { *

This API is only supported by Tuner HAL 1.1 or higher. Unsupported version would cause * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version. * + *

Default value is {@link #VIDEO_STREAM_TYPE_UNDEFINED}. + * * @param videoStreamType the video stream type to set. */ @NonNull @@ -293,13 +312,30 @@ public class AvSettings extends Settings { return this; } + /** + * Sets whether secure memory should be used. + * + *

This API is only supported by Tuner HAL 2.0 or higher. Unsupported version would cause + * no-op. Use {@link TunerVersionChecker#getTunerVersion()} to check the version. + * + *

Default value is {@code false}. + */ + @NonNull + public Builder setUseSecureMemory(boolean useSecureMemory) { + if (TunerVersionChecker.checkHigherOrEqualVersionTo( + TunerVersionChecker.TUNER_VERSION_2_0, "setSecureMemory")) { + mUseSecureMemory = useSecureMemory; + } + return this; + } + /** * Builds a {@link AvSettings} object. */ @NonNull public AvSettings build() { - return new AvSettings(mMainType, mIsAudio, mIsPassthrough, - mAudioStreamType, mVideoStreamType); + return new AvSettings(mMainType, mIsAudio, mIsPassthrough, mAudioStreamType, + mVideoStreamType, mUseSecureMemory); } } } diff --git a/media/java/android/media/tv/tuner/filter/RecordSettings.java b/media/java/android/media/tv/tuner/filter/RecordSettings.java index cd703651f2fac..d34581da29cb8 100644 --- a/media/java/android/media/tv/tuner/filter/RecordSettings.java +++ b/media/java/android/media/tv/tuner/filter/RecordSettings.java @@ -20,11 +20,11 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.SystemApi; import android.hardware.tv.tuner.DemuxRecordScIndexType; +import android.hardware.tv.tuner.DemuxScAvcIndex; import android.hardware.tv.tuner.DemuxScHevcIndex; import android.hardware.tv.tuner.DemuxScIndex; import android.hardware.tv.tuner.DemuxTsIndex; import android.media.tv.tuner.TunerUtils; - import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -139,7 +139,7 @@ public class RecordSettings extends Settings { /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = "INDEX_TYPE_", value = - {INDEX_TYPE_NONE, INDEX_TYPE_SC, INDEX_TYPE_SC_HEVC}) + {INDEX_TYPE_NONE, INDEX_TYPE_SC, INDEX_TYPE_SC_HEVC, INDEX_TYPE_SC_AVC}) public @interface ScIndexType {} /** @@ -154,6 +154,10 @@ public class RecordSettings extends Settings { * Start Code index for HEVC. */ public static final int INDEX_TYPE_SC_HEVC = DemuxRecordScIndexType.SC_HEVC; + /** + * Start Code index for AVC. + */ + public static final int INDEX_TYPE_SC_AVC = DemuxRecordScIndexType.SC_AVC; /** * Indexes can be tagged by Start Code in PES (Packetized Elementary Stream) @@ -187,23 +191,23 @@ public class RecordSettings extends Settings { /** * All blocks are coded as I blocks. */ - public static final int SC_INDEX_I_SLICE = DemuxScIndex.I_SLICE; + public static final int SC_INDEX_I_SLICE = DemuxScAvcIndex.I_SLICE << 4; /** * Blocks are coded as I or P blocks. */ - public static final int SC_INDEX_P_SLICE = DemuxScIndex.P_SLICE; + public static final int SC_INDEX_P_SLICE = DemuxScAvcIndex.P_SLICE << 4; /** * Blocks are coded as I, P or B blocks. */ - public static final int SC_INDEX_B_SLICE = DemuxScIndex.B_SLICE; + public static final int SC_INDEX_B_SLICE = DemuxScAvcIndex.B_SLICE << 4; /** * A so-called switching I slice that is coded. */ - public static final int SC_INDEX_SI_SLICE = DemuxScIndex.SI_SLICE; + public static final int SC_INDEX_SI_SLICE = DemuxScAvcIndex.SI_SLICE << 4; /** * A so-called switching P slice that is coded. */ - public static final int SC_INDEX_SP_SLICE = DemuxScIndex.SP_SLICE; + public static final int SC_INDEX_SP_SLICE = DemuxScAvcIndex.SP_SLICE << 4; /** * Indexes can be tagged by NAL unit group in HEVC according to ISO/IEC 23008-2. diff --git a/media/java/android/media/tv/tuner/filter/SectionSettingsWithTableInfo.java b/media/java/android/media/tv/tuner/filter/SectionSettingsWithTableInfo.java index fc6451fd96bcb..ff8f796455c6a 100644 --- a/media/java/android/media/tv/tuner/filter/SectionSettingsWithTableInfo.java +++ b/media/java/android/media/tv/tuner/filter/SectionSettingsWithTableInfo.java @@ -18,6 +18,7 @@ package android.media.tv.tuner.filter; import android.annotation.NonNull; import android.annotation.SystemApi; +import android.hardware.tv.tuner.Constant; /** * Table information for Section Filter. @@ -26,6 +27,12 @@ import android.annotation.SystemApi; */ @SystemApi public class SectionSettingsWithTableInfo extends SectionSettings { + /** + * The invalid version number of {@link SectionSettingsWithTableInfo}. Tuner HAL will ignore the + * {@link SectionSettingsWithTableInfo} version number if this invalid version is set. + */ + public static final int INVALID_TABLE_INFO_VERSION = Constant.INVALID_TABINFO_VERSION; + private final int mTableId; private final int mVersion; @@ -64,7 +71,7 @@ public class SectionSettingsWithTableInfo extends SectionSettings { */ public static class Builder extends SectionSettings.Builder { private int mTableId; - private int mVersion; + private int mVersion = INVALID_TABLE_INFO_VERSION; private Builder(int mainType) { super(mainType); diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp index c4dfee42c3cd8..afa02b3793363 100644 --- a/media/jni/android_media_tv_Tuner.cpp +++ b/media/jni/android_media_tv_Tuner.cpp @@ -693,6 +693,10 @@ void FilterClientCallbackImpl::getTsRecordEvent(jobjectArray &arr, const int siz sc = tsRecordEvent.scIndexMask.get(); } else if (tsRecordEvent.scIndexMask.getTag() == DemuxFilterScIndexMask::Tag::scHevc) { sc = tsRecordEvent.scIndexMask.get(); + } else if (tsRecordEvent.scIndexMask.getTag() == DemuxFilterScIndexMask::Tag::scAvc) { + sc = tsRecordEvent.scIndexMask.get(); + // Java uses the values defined by HIDL HAL. Left shift 4 bits. + sc = sc << 4; } jint ts = tsRecordEvent.tsIndexMask; @@ -3391,8 +3395,11 @@ static DemuxFilterAvSettings getFilterAvSettings(JNIEnv *env, const jobject& set jclass clazz = env->FindClass("android/media/tv/tuner/filter/AvSettings"); bool isPassthrough = env->GetBooleanField(settings, env->GetFieldID(clazz, "mIsPassthrough", "Z")); - DemuxFilterAvSettings filterAvSettings { - .isPassthrough = isPassthrough, + bool isSecureMemory = + env->GetBooleanField(settings, env->GetFieldID(clazz, "mUseSecureMemory", "Z")); + DemuxFilterAvSettings filterAvSettings{ + .isPassthrough = isPassthrough, + .isSecureMemory = isSecureMemory, }; return filterAvSettings; } @@ -3440,6 +3447,11 @@ static DemuxFilterRecordSettings getFilterRecordSettings(JNIEnv *env, const jobj env->GetIntField(settings, env->GetFieldID(clazz, "mScIndexType", "I"))); jint scIndexMask = env->GetIntField(settings, env->GetFieldID(clazz, "mScIndexMask", "I")); + // Backward compatibility for S- apps. + if (scIndexType == DemuxRecordScIndexType::SC && + scIndexMask > static_cast(DemuxScIndex::SEQUENCE)) { + scIndexType = DemuxRecordScIndexType::SC_AVC; + } DemuxFilterRecordSettings filterRecordSettings { .tsIndexMask = tsIndexMask, .scIndexType = scIndexType, @@ -3448,6 +3460,9 @@ static DemuxFilterRecordSettings getFilterRecordSettings(JNIEnv *env, const jobj filterRecordSettings.scIndexMask.set(scIndexMask); } else if (scIndexType == DemuxRecordScIndexType::SC_HEVC) { filterRecordSettings.scIndexMask.set(scIndexMask); + } else if (scIndexType == DemuxRecordScIndexType::SC_AVC) { + // Java uses the values defined by HIDL HAL. Right shift 4 bits. + filterRecordSettings.scIndexMask.set(scIndexMask >> 4); } return filterRecordSettings; }