From cfd146f5fb5df2fd8fe71616711f254f6c625aef Mon Sep 17 00:00:00 2001 From: Hongguang Date: Tue, 11 Jan 2022 12:54:12 -0800 Subject: [PATCH] Add API to filter out unnecessary PIDs from frontend output. Bug: 213287138 Fix: 213287138 Test: atest android.media.tv.tuner.cts on AIDL and HIDL HALs Change-Id: Ie5317c080e43fac2371d6cea46cfc8e22a4e42cf --- core/api/system-current.txt | 1 + media/java/android/media/tv/tuner/Tuner.java | 32 +++++++++++++++++++- media/jni/android_media_tv_Tuner.cpp | 16 ++++++++++ media/jni/android_media_tv_Tuner.h | 1 + media/jni/tuner/FrontendClient.cpp | 9 ++++++ media/jni/tuner/FrontendClient.h | 5 +++ 6 files changed, 63 insertions(+), 1 deletion(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index f48d956f0de79..bc86cccbf44e9 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -6495,6 +6495,7 @@ package android.media.tv.tuner { method @Nullable public android.media.tv.tuner.Lnb openLnbByName(@NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.media.tv.tuner.LnbCallback); method @Nullable @RequiresPermission(android.Manifest.permission.ACCESS_TV_SHARED_FILTER) public static android.media.tv.tuner.filter.SharedFilter openSharedFilter(@NonNull android.content.Context, @NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.media.tv.tuner.filter.SharedFilterCallback); method @Nullable public android.media.tv.tuner.filter.TimeFilter openTimeFilter(); + method public int removeOutputPid(@IntRange(from=0) int); method public int scan(@NonNull android.media.tv.tuner.frontend.FrontendSettings, int, @NonNull java.util.concurrent.Executor, @NonNull android.media.tv.tuner.frontend.ScanCallback); method public int setLnaEnabled(boolean); method public int setMaxNumberOfFrontends(int, @IntRange(from=0) int); diff --git a/media/java/android/media/tv/tuner/Tuner.java b/media/java/android/media/tv/tuner/Tuner.java index 4128abf03e071..9fbbd4b559e9c 100644 --- a/media/java/android/media/tv/tuner/Tuner.java +++ b/media/java/android/media/tv/tuner/Tuner.java @@ -691,7 +691,7 @@ public class Tuner implements AutoCloseable { private native String nativeGetFrontendHardwareInfo(); private native int nativeSetMaxNumberOfFrontends(int frontendType, int maxNumber); private native int nativeGetMaxNumberOfFrontends(int frontendType); - + private native int nativeRemoveOutputPid(int pid); private native Lnb nativeOpenLnbByHandle(int handle); private native Lnb nativeOpenLnbByName(String name); @@ -1238,6 +1238,36 @@ public class Tuner implements AutoCloseable { } } + /** + * Filter out unnecessary PID (packet identifier) from frontend output. + * + *

It is used by the client to remove some video or audio PIDs of other program to reduce the + * total amount of recorded TS. + * + *

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. + * + * @return result status of the operation. Unsupported version or if current active frontend + * doesn’t support PID filtering out would return {@link #RESULT_UNAVAILABLE}. + * @throws IllegalStateException if there is no active frontend currently. + */ + @Result + public int removeOutputPid(@IntRange(from = 0) int pid) { + mFrontendLock.lock(); + try { + if (!TunerVersionChecker.checkHigherOrEqualVersionTo( + TunerVersionChecker.TUNER_VERSION_2_0, "Remove output PID")) { + return RESULT_UNAVAILABLE; + } + if (mFrontend == null) { + throw new IllegalStateException("frontend is not initialized"); + } + return nativeRemoveOutputPid(pid); + } finally { + mFrontendLock.unlock(); + } + } + /** * Gets the currently initialized and activated frontend information. To get all the available * frontend info on the device, use {@link getAvailableFrontendInfos()}. diff --git a/media/jni/android_media_tv_Tuner.cpp b/media/jni/android_media_tv_Tuner.cpp index 9572e18066433..c3449dc848448 100644 --- a/media/jni/android_media_tv_Tuner.cpp +++ b/media/jni/android_media_tv_Tuner.cpp @@ -1595,6 +1595,15 @@ int32_t JTuner::getMaxNumberOfFrontends(int32_t type) { return mTunerClient->getMaxNumberOfFrontends(static_cast(type)); } +jint JTuner::removeOutputPid(int32_t pid) { + if (mFeClient == nullptr) { + ALOGE("frontend is not initialized"); + return (jint)Result::INVALID_STATE; + } + + return (jint)mFeClient->removeOutputPid(pid); +} + jobject JTuner::openLnbByHandle(int handle) { if (mTunerClient == nullptr) { return nullptr; @@ -4313,6 +4322,11 @@ static jint android_media_tv_Tuner_get_maximum_frontends(JNIEnv *env, jobject th return tuner->getMaxNumberOfFrontends(type); } +static jint android_media_tv_Tuner_remove_output_pid(JNIEnv *env, jobject thiz, jint pid) { + sp tuner = getTuner(env, thiz); + return tuner->removeOutputPid(pid); +} + static jint android_media_tv_Tuner_close_frontend(JNIEnv* env, jobject thiz, jint /* handle */) { sp tuner = getTuner(env, thiz); return tuner->closeFrontend(); @@ -4628,6 +4642,8 @@ static const JNINativeMethod gTunerMethods[] = { (void *)android_media_tv_Tuner_set_maximum_frontends }, { "nativeGetMaxNumberOfFrontends", "(I)I", (void *)android_media_tv_Tuner_get_maximum_frontends }, + { "nativeRemoveOutputPid", "(I)I", + (void *)android_media_tv_Tuner_remove_output_pid }, }; static const JNINativeMethod gFilterMethods[] = { diff --git a/media/jni/android_media_tv_Tuner.h b/media/jni/android_media_tv_Tuner.h index f1b31e3520b14..f7e8b609956bf 100644 --- a/media/jni/android_media_tv_Tuner.h +++ b/media/jni/android_media_tv_Tuner.h @@ -203,6 +203,7 @@ struct JTuner : public RefBase { Result getFrontendHardwareInfo(string& info); jint setMaxNumberOfFrontends(int32_t frontendType, int32_t maxNumber); int32_t getMaxNumberOfFrontends(int32_t frontendType); + jint removeOutputPid(int32_t pid); jweak getObject(); diff --git a/media/jni/tuner/FrontendClient.cpp b/media/jni/tuner/FrontendClient.cpp index 0fdd8d8773f40..bea0342293c07 100644 --- a/media/jni/tuner/FrontendClient.cpp +++ b/media/jni/tuner/FrontendClient.cpp @@ -143,6 +143,15 @@ Result FrontendClient::getHardwareInfo(string& info) { return Result::INVALID_STATE; } +Result FrontendClient::removeOutputPid(int32_t pid) { + if (mTunerFrontend != nullptr) { + Status s = mTunerFrontend->removeOutputPid(pid); + return ClientHelper::getServiceSpecificErrorCode(s); + } + + return Result::INVALID_STATE; +} + shared_ptr FrontendClient::getAidlFrontend() { return mTunerFrontend; } diff --git a/media/jni/tuner/FrontendClient.h b/media/jni/tuner/FrontendClient.h index 77d909804cf05..c6838c85dfc4f 100644 --- a/media/jni/tuner/FrontendClient.h +++ b/media/jni/tuner/FrontendClient.h @@ -120,6 +120,11 @@ public: */ Result getHardwareInfo(string& info); + /** + * Filter out unnecessary PID from frontend output. + */ + Result removeOutputPid(int32_t pid); + int32_t getId(); shared_ptr getAidlFrontend();