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
This commit is contained in:
Hongguang
2022-01-11 12:54:12 -08:00
committed by Hongguang Chen
parent 2e6243d900
commit cfd146f5fb
6 changed files with 63 additions and 1 deletions

View File

@@ -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);

View File

@@ -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.
*
* <p>It is used by the client to remove some video or audio PIDs of other program to reduce the
* total amount of recorded TS.
*
* <p>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()}.

View File

@@ -1595,6 +1595,15 @@ int32_t JTuner::getMaxNumberOfFrontends(int32_t type) {
return mTunerClient->getMaxNumberOfFrontends(static_cast<FrontendType>(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<JTuner> tuner = getTuner(env, thiz);
return tuner->removeOutputPid(pid);
}
static jint android_media_tv_Tuner_close_frontend(JNIEnv* env, jobject thiz, jint /* handle */) {
sp<JTuner> 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[] = {

View File

@@ -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();

View File

@@ -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<ITunerFrontend> FrontendClient::getAidlFrontend() {
return mTunerFrontend;
}

View File

@@ -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<ITunerFrontend> getAidlFrontend();