diff options
5 files changed, 217 insertions, 0 deletions
diff --git a/media/java/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl b/media/java/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl index 20efaa1e0833..b21bc89e2f37 100644 --- a/media/java/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl +++ b/media/java/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl @@ -19,6 +19,7 @@ package android.media.tv.tunerresourcemanager; import android.media.tv.tunerresourcemanager.CasSessionRequest; import android.media.tv.tunerresourcemanager.IResourcesReclaimListener; import android.media.tv.tunerresourcemanager.ResourceClientProfile; +import android.media.tv.tunerresourcemanager.TunerDemuxRequest; import android.media.tv.tunerresourcemanager.TunerFrontendInfo; import android.media.tv.tunerresourcemanager.TunerFrontendRequest; import android.media.tv.tunerresourcemanager.TunerLnbRequest; @@ -148,6 +149,29 @@ interface ITunerResourceManager { void shareFrontend(in int selfClientId, in int targetClientId); /* + * This API is used by the Tuner framework to request an available demux from the TunerHAL. + * + * <p>There are three possible scenarios: + * <ul> + * <li>If there is demux available, the API would send the handle back. + * + * <li>If no Demux is available but the current request info can show higher priority than + * other uses of demuxes, the API will send + * {@link IResourcesReclaimListener#onReclaimResources()} to the {@link Tuner}. Tuner would + * handle the resource reclaim on the holder of lower priority and notify the holder of its + * resource loss. + * + * <li>If no demux can be granted, the API would return false. + * <ul> + * + * @param request {@link TunerDemuxRequest} information of the current request. + * @param demuxHandle a one-element array to return the granted demux handle. + * + * @return true if there is demux granted. + */ + boolean requestDemux(in TunerDemuxRequest request, out int[] demuxHandle); + + /* * This API is used by the Tuner framework to request an available Cas session. This session * needs to be under the CAS system with the id indicated in the {@code request}. * @@ -210,6 +234,15 @@ interface ITunerResourceManager { void releaseFrontend(in int frontendId); /* + * Notifies the TRM that the Demux with the given handle was released. + * + * <p>Client must call this whenever it releases a demux. + * + * @param demuxHandle the handle of the released Tuner Demux. + */ + void releaseDemux(in int demuxHandle); + + /* * Notifies the TRM that the given Cas session has been released. * * <p>Client must call this whenever it releases a Cas session. diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl b/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl new file mode 100644 index 000000000000..919a215a9ce5 --- /dev/null +++ b/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.aidl @@ -0,0 +1,24 @@ +/* + * 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.tunerresourcemanager; + +/** + * Information required to request a Tuner Demux. + * + * @hide + */ +parcelable TunerDemuxRequest;
\ No newline at end of file diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.java b/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.java new file mode 100644 index 000000000000..34a77616f62e --- /dev/null +++ b/media/java/android/media/tv/tunerresourcemanager/TunerDemuxRequest.java @@ -0,0 +1,96 @@ +/* + * 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.tunerresourcemanager; + +import android.annotation.NonNull; +import android.os.Parcel; +import android.os.Parcelable; +import android.util.Log; + +/** + * Information required to request a Tuner Demux. + * + * @hide + */ +public final class TunerDemuxRequest implements Parcelable { + static final String TAG = "TunerDemuxRequest"; + + public static final + @NonNull + Parcelable.Creator<TunerDemuxRequest> CREATOR = + new Parcelable.Creator<TunerDemuxRequest>() { + @Override + public TunerDemuxRequest createFromParcel(Parcel source) { + try { + return new TunerDemuxRequest(source); + } catch (Exception e) { + Log.e(TAG, "Exception creating TunerDemuxRequest from parcel", e); + return null; + } + } + + @Override + public TunerDemuxRequest[] newArray(int size) { + return new TunerDemuxRequest[size]; + } + }; + + /** + * Client id of the client that sends the request. + */ + private final int mClientId; + + private TunerDemuxRequest(@NonNull Parcel source) { + mClientId = source.readInt(); + } + + /** + * Constructs a new {@link TunerDemuxRequest} with the given parameters. + * + * @param clientId id of the client. + */ + public TunerDemuxRequest(int clientId) { + mClientId = clientId; + } + + /** + * Returns the id of the client. + */ + public int getClientId() { + return mClientId; + } + + // Parcelable + @Override + public int describeContents() { + return 0; + } + + @NonNull + @Override + public String toString() { + StringBuilder b = new StringBuilder(128); + b.append("TunerDemuxRequest {clientId=").append(mClientId); + b.append("}"); + return b.toString(); + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeInt(mClientId); + } +} diff --git a/media/java/android/media/tv/tunerresourcemanager/TunerResourceManager.java b/media/java/android/media/tv/tunerresourcemanager/TunerResourceManager.java index 7c11ed485ced..1c1d7fab3107 100644 --- a/media/java/android/media/tv/tunerresourcemanager/TunerResourceManager.java +++ b/media/java/android/media/tv/tunerresourcemanager/TunerResourceManager.java @@ -65,6 +65,7 @@ public class TunerResourceManager { public static final int INVALID_LNB_ID = -1; public static final int INVALID_TV_INPUT_DEVICE_ID = -1; public static final int INVALID_TV_INPUT_PORT_ID = -1; + public static final int INVALID_RESOURCE_HANDLE = -1; private final ITunerResourceManager mService; private final int mUserId; @@ -260,6 +261,37 @@ public class TunerResourceManager { } /** + * Requests a Tuner Demux resource. + * + * <p>There are three possible scenarios: + * <ul> + * <li>If there is Demux available, the API would send the handle back. + * + * <li>If no Demux is available but the current request has a higher priority than other uses of + * demuxes, the API will send {@link IResourcesReclaimListener#onReclaimResources()} to the + * {@link Tuner}. Tuner would handle the resource reclaim on the holder of lower priority and + * notify the holder of its resource loss. + * + * <li>If no Demux system can be granted, the API would return false. + * <ul> + * + * @param request {@link TunerDemuxRequest} information of the current request. + * @param demuxHandle a one-element array to return the granted Demux handle. + * If no Demux granted, this will return {@link #INVALID_RESOURCE_HANDLE}. + * + * @return true if there is Demux granted. + */ + public boolean requestDemux(@NonNull TunerDemuxRequest request, @NonNull int[] demuxHandle) { + boolean result = false; + try { + result = mService.requestDemux(request, demuxHandle); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + return result; + } + + /** * Requests a CAS session resource. * * <p>There are three possible scenarios: @@ -345,6 +377,21 @@ public class TunerResourceManager { } /** + * Notifies the TRM that the Demux with the given handle has been released. + * + * <p>Client must call this whenever it releases an Demux. + * + * @param demuxHandle the handle of the released Tuner Demux. + */ + public void releaseDemux(int demuxHandle) { + try { + mService.releaseDemux(demuxHandle); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * Notifies the TRM that the given Cas session has been released. * * <p>Client must call this whenever it releases a Cas session. diff --git a/services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java b/services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java index 04d551d0f84e..2d3fc748b7fd 100644 --- a/services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java +++ b/services/core/java/com/android/server/tv/tunerresourcemanager/TunerResourceManagerService.java @@ -24,6 +24,7 @@ import android.media.tv.tunerresourcemanager.CasSessionRequest; import android.media.tv.tunerresourcemanager.IResourcesReclaimListener; import android.media.tv.tunerresourcemanager.ITunerResourceManager; import android.media.tv.tunerresourcemanager.ResourceClientProfile; +import android.media.tv.tunerresourcemanager.TunerDemuxRequest; import android.media.tv.tunerresourcemanager.TunerFrontendInfo; import android.media.tv.tunerresourcemanager.TunerFrontendRequest; import android.media.tv.tunerresourcemanager.TunerLnbRequest; @@ -189,6 +190,15 @@ public class TunerResourceManagerService extends SystemService { } @Override + public boolean requestDemux(@NonNull TunerDemuxRequest request, + @NonNull int[] demuxHandle) { + if (DEBUG) { + Slog.d(TAG, "requestDemux(request=" + request + ")"); + } + return true; + } + + @Override public boolean requestCasSession( @NonNull CasSessionRequest request, @NonNull int[] sessionResourceId) { if (DEBUG) { @@ -214,6 +224,13 @@ public class TunerResourceManagerService extends SystemService { } @Override + public void releaseDemux(int demuxHandle) { + if (DEBUG) { + Slog.d(TAG, "releaseDemux(demuxHandle=" + demuxHandle + ")"); + } + } + + @Override public void releaseCasSession(int sessionResourceId) { if (DEBUG) { Slog.d(TAG, "releaseCasSession(sessionResourceId=" + sessionResourceId + ")"); |