Loading media/java/android/media/MediaCas.java +10 −10 Original line number Diff line number Diff line Loading @@ -388,7 +388,7 @@ public final class MediaCas implements AutoCloseable { @Override public void onReclaimResources() { synchronized (mSessionMap) { mSessionMap.forEach((casSession, sessionResourceId) -> casSession.close()); mSessionMap.forEach((casSession, sessionResourceHandle) -> casSession.close()); } mEventHandler.sendMessage(mEventHandler.obtainMessage( EventHandler.MSG_CAS_RESOURCE_LOST)); Loading Loading @@ -868,7 +868,7 @@ public final class MediaCas implements AutoCloseable { } } private int getSessionResourceId() throws MediaCasException { private int getSessionResourceHandle() throws MediaCasException { validateInternalStates(); int[] sessionResourceHandle = new int[1]; Loading @@ -884,11 +884,11 @@ public final class MediaCas implements AutoCloseable { return sessionResourceHandle[0]; } private void addSessionToResourceMap(Session session, int sessionResourceId) { private void addSessionToResourceMap(Session session, int sessionResourceHandle) { if (sessionResourceId != -1) { if (sessionResourceHandle != TunerResourceManager.INVALID_RESOURCE_HANDLE) { synchronized (mSessionMap) { mSessionMap.put(session, sessionResourceId); mSessionMap.put(session, sessionResourceHandle); } } } Loading Loading @@ -918,13 +918,13 @@ public final class MediaCas implements AutoCloseable { * @throws MediaCasStateException for CAS-specific state exceptions. */ public Session openSession() throws MediaCasException { int sessionResourceId = getSessionResourceId(); int sessionResourceHandle = getSessionResourceHandle(); try { OpenSessionCallback cb = new OpenSessionCallback(); mICas.openSession(cb); MediaCasException.throwExceptionIfNeeded(cb.mStatus); addSessionToResourceMap(cb.mSession, sessionResourceId); addSessionToResourceMap(cb.mSession, sessionResourceHandle); return cb.mSession; } catch (RemoteException e) { cleanupAndRethrowIllegalState(); Loading Loading @@ -952,7 +952,7 @@ public final class MediaCas implements AutoCloseable { @Nullable public Session openSession(@SessionUsage int sessionUsage, @ScramblingMode int scramblingMode) throws MediaCasException { int sessionResourceId = getSessionResourceId(); int sessionResourceHandle = getSessionResourceHandle(); if (mICasV12 == null) { Log.d(TAG, "Open Session with scrambling mode is only supported by cas@1.2+ interface"); Loading @@ -963,7 +963,7 @@ public final class MediaCas implements AutoCloseable { OpenSession_1_2_Callback cb = new OpenSession_1_2_Callback(); mICasV12.openSession_1_2(sessionUsage, scramblingMode, cb); MediaCasException.throwExceptionIfNeeded(cb.mStatus); addSessionToResourceMap(cb.mSession, sessionResourceId); addSessionToResourceMap(cb.mSession, sessionResourceHandle); return cb.mSession; } catch (RemoteException e) { cleanupAndRethrowIllegalState(); Loading media/java/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl +5 −5 Original line number Diff line number Diff line Loading @@ -218,11 +218,11 @@ interface ITunerResourceManager { * <p><strong>Note:</strong> {@link #updateCasInfo(int, int)} must be called before this request. * * @param request {@link CasSessionRequest} information of the current request. * @param sessionResourceId a one-element array to return the granted cas session id. * @param casSessionHandle a one-element array to return the granted cas session handle. * * @return true if there is CAS session granted. */ boolean requestCasSession(in CasSessionRequest request, out int[] sessionResourceId); boolean requestCasSession(in CasSessionRequest request, out int[] casSessionHandle); /* * This API is used by the Tuner framework to request an available Lnb from the TunerHAL. Loading Loading @@ -276,7 +276,7 @@ interface ITunerResourceManager { * * <p>Client must call this whenever it releases a descrambler. * * @param demuxHandle the handle of the released Tuner Descrambler. * @param descramblerHandle the handle of the released Tuner Descrambler. * @param clientId the id of the client that is releasing the descrambler. */ void releaseDescrambler(in int descramblerHandle, int clientId); Loading @@ -288,10 +288,10 @@ interface ITunerResourceManager { * * <p><strong>Note:</strong> {@link #updateCasInfo(int, int)} must be called before this release. * * @param sessionResourceId the id of the released CAS session. * @param casSessionHandle the handle of the released CAS session. * @param clientId the id of the client that is releasing the cas session. */ void releaseCasSession(in int sessionResourceId, int clientId); void releaseCasSession(in int casSessionHandle, int clientId); /* * Notifies the TRM that the Lnb with the given handle was released. Loading media/java/android/media/tv/tunerresourcemanager/TunerResourceManager.java +7 −8 Original line number Diff line number Diff line Loading @@ -362,17 +362,16 @@ public class TunerResourceManager { * request. * * @param request {@link CasSessionRequest} information of the current request. * @param sessionResourceId a one-element array to return the granted cas session id. * If no CAS granted, this will return * {@link #INVALID_CAS_SESSION_RESOURCE_ID}. * @param casSessionHandle a one-element array to return the granted cas session handel. * If no CAS granted, this will return {@link #INVALID_RESOURCE_HANDLE}. * * @return true if there is CAS session granted. */ public boolean requestCasSession(@NonNull CasSessionRequest request, @NonNull int[] sessionResourceId) { @NonNull int[] casSessionHandle) { boolean result = false; try { result = mService.requestCasSession(request, sessionResourceId); result = mService.requestCasSession(request, casSessionHandle); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading Loading @@ -471,12 +470,12 @@ public class TunerResourceManager { * <p><strong>Note:</strong> {@link #updateCasInfo(int, int)} must be called before this * release. * * @param sessionResourceId the id of the released CAS session. * @param casSessionHandle the handle of the released CAS session. * @param clientId the id of the client that is releasing the cas session. */ public void releaseCasSession(int sessionResourceId, int clientId) { public void releaseCasSession(int casSessionHandle, int clientId) { try { mService.releaseCasSession(sessionResourceId, clientId); mService.releaseCasSession(casSessionHandle, clientId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading services/core/java/com/android/server/tv/tunerresourcemanager/CasResource.java 0 → 100644 +152 −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 com.android.server.tv.tunerresourcemanager; import java.util.HashMap; import java.util.Map; import java.util.Set; /** * A Cas resource object used by the Tuner Resource Manager to record the cas * information. * * @hide */ public final class CasResource { private final int mSystemId; private int mMaxSessionNum; private int mAvailableSessionNum; /** * The owner clients' ids when part of the Cas is occupied. */ private Map<Integer, Integer> mOwnerClientIdsToSessionNum = new HashMap<>(); private CasResource(Builder builder) { this.mSystemId = builder.mSystemId; this.mMaxSessionNum = builder.mMaxSessionNum; this.mAvailableSessionNum = builder.mMaxSessionNum; } public int getSystemId() { return mSystemId; } public int getMaxSessionNum() { return mMaxSessionNum; } public int getUsedSessionNum() { return (mMaxSessionNum - mAvailableSessionNum); } public boolean isFullyUsed() { return mAvailableSessionNum == 0; } /** * Update max session number. * * @param maxSessionNum the new max session num. */ public void updateMaxSessionNum(int maxSessionNum) { mAvailableSessionNum = Math.max( 0, mAvailableSessionNum + (maxSessionNum - mMaxSessionNum)); mMaxSessionNum = maxSessionNum; } /** * Set an owner for the cas * * @param ownerId the client id of the owner. */ public void setOwner(int ownerId) { int sessionNum = mOwnerClientIdsToSessionNum.get(ownerId) == null ? 1 : (mOwnerClientIdsToSessionNum.get(ownerId) + 1); mOwnerClientIdsToSessionNum.put(ownerId, sessionNum); mAvailableSessionNum--; } /** * Remove an owner of the Cas. * * @param ownerId the removing client id of the owner. */ public void removeOwner(int ownerId) { mAvailableSessionNum += mOwnerClientIdsToSessionNum.get(ownerId); mOwnerClientIdsToSessionNum.remove(ownerId); } public Set<Integer> getOwnerClientIds() { return mOwnerClientIdsToSessionNum.keySet(); } @Override public String toString() { return "CasResource[systemId=" + this.mSystemId + ", isFullyUsed=" + (this.mAvailableSessionNum == 0) + ", maxSessionNum=" + this.mMaxSessionNum + ", ownerClients=" + ownersMapToString() + "]"; } /** * Builder class for {@link CasResource}. */ public static class Builder { private int mSystemId; private int mMaxSessionNum; Builder(int systemId) { this.mSystemId = systemId; } /** * Builder for {@link CasResource}. * * @param maxSessionNum the max session num the current Cas has. */ public Builder maxSessionNum(int maxSessionNum) { this.mMaxSessionNum = maxSessionNum; return this; } /** * Build a {@link CasResource}. * * @return {@link CasResource}. */ public CasResource build() { CasResource cas = new CasResource(this); return cas; } } private String ownersMapToString() { StringBuilder string = new StringBuilder("{"); for (int clienId : mOwnerClientIdsToSessionNum.keySet()) { string.append(" clientId=") .append(clienId) .append(", owns session num=") .append(mOwnerClientIdsToSessionNum.get(clienId)) .append(","); } return string.append("}").toString(); } } services/core/java/com/android/server/tv/tunerresourcemanager/ClientProfile.java +27 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import java.util.Set; public final class ClientProfile { public static final int INVALID_GROUP_ID = -1; public static final int INVALID_RESOURCE_ID = -1; /** * Client id sent to the client when registering with Loading Loading @@ -56,7 +57,6 @@ public final class ClientProfile { * also lose their resources. */ private int mGroupId = INVALID_GROUP_ID; /** * Optional nice value for TRM to reduce client’s priority. */ Loading @@ -72,6 +72,11 @@ public final class ClientProfile { */ private Set<Integer> mUsingLnbIds = new HashSet<>(); /** * List of the Cas system ids that are used by the current client. */ private int mUsingCasSystemId = INVALID_RESOURCE_ID; /** * Optional arbitrary priority value given by the client. * Loading Loading @@ -171,12 +176,33 @@ public final class ClientProfile { mUsingLnbIds.remove(lnbId); } /** * Set when the client starts to use a Cas system. * * @param casSystemId cas being used. */ public void useCas(int casSystemId) { mUsingCasSystemId = casSystemId; } public int getInUseCasSystemId() { return mUsingCasSystemId; } /** * Called when the client released a Cas System. */ public void releaseCas() { mUsingCasSystemId = INVALID_RESOURCE_ID; } /** * Called to reclaim all the resources being used by the current client. */ public void reclaimAllResources() { mUsingFrontendIds.clear(); mUsingLnbIds.clear(); mUsingCasSystemId = INVALID_RESOURCE_ID; } @Override Loading Loading
media/java/android/media/MediaCas.java +10 −10 Original line number Diff line number Diff line Loading @@ -388,7 +388,7 @@ public final class MediaCas implements AutoCloseable { @Override public void onReclaimResources() { synchronized (mSessionMap) { mSessionMap.forEach((casSession, sessionResourceId) -> casSession.close()); mSessionMap.forEach((casSession, sessionResourceHandle) -> casSession.close()); } mEventHandler.sendMessage(mEventHandler.obtainMessage( EventHandler.MSG_CAS_RESOURCE_LOST)); Loading Loading @@ -868,7 +868,7 @@ public final class MediaCas implements AutoCloseable { } } private int getSessionResourceId() throws MediaCasException { private int getSessionResourceHandle() throws MediaCasException { validateInternalStates(); int[] sessionResourceHandle = new int[1]; Loading @@ -884,11 +884,11 @@ public final class MediaCas implements AutoCloseable { return sessionResourceHandle[0]; } private void addSessionToResourceMap(Session session, int sessionResourceId) { private void addSessionToResourceMap(Session session, int sessionResourceHandle) { if (sessionResourceId != -1) { if (sessionResourceHandle != TunerResourceManager.INVALID_RESOURCE_HANDLE) { synchronized (mSessionMap) { mSessionMap.put(session, sessionResourceId); mSessionMap.put(session, sessionResourceHandle); } } } Loading Loading @@ -918,13 +918,13 @@ public final class MediaCas implements AutoCloseable { * @throws MediaCasStateException for CAS-specific state exceptions. */ public Session openSession() throws MediaCasException { int sessionResourceId = getSessionResourceId(); int sessionResourceHandle = getSessionResourceHandle(); try { OpenSessionCallback cb = new OpenSessionCallback(); mICas.openSession(cb); MediaCasException.throwExceptionIfNeeded(cb.mStatus); addSessionToResourceMap(cb.mSession, sessionResourceId); addSessionToResourceMap(cb.mSession, sessionResourceHandle); return cb.mSession; } catch (RemoteException e) { cleanupAndRethrowIllegalState(); Loading Loading @@ -952,7 +952,7 @@ public final class MediaCas implements AutoCloseable { @Nullable public Session openSession(@SessionUsage int sessionUsage, @ScramblingMode int scramblingMode) throws MediaCasException { int sessionResourceId = getSessionResourceId(); int sessionResourceHandle = getSessionResourceHandle(); if (mICasV12 == null) { Log.d(TAG, "Open Session with scrambling mode is only supported by cas@1.2+ interface"); Loading @@ -963,7 +963,7 @@ public final class MediaCas implements AutoCloseable { OpenSession_1_2_Callback cb = new OpenSession_1_2_Callback(); mICasV12.openSession_1_2(sessionUsage, scramblingMode, cb); MediaCasException.throwExceptionIfNeeded(cb.mStatus); addSessionToResourceMap(cb.mSession, sessionResourceId); addSessionToResourceMap(cb.mSession, sessionResourceHandle); return cb.mSession; } catch (RemoteException e) { cleanupAndRethrowIllegalState(); Loading
media/java/android/media/tv/tunerresourcemanager/ITunerResourceManager.aidl +5 −5 Original line number Diff line number Diff line Loading @@ -218,11 +218,11 @@ interface ITunerResourceManager { * <p><strong>Note:</strong> {@link #updateCasInfo(int, int)} must be called before this request. * * @param request {@link CasSessionRequest} information of the current request. * @param sessionResourceId a one-element array to return the granted cas session id. * @param casSessionHandle a one-element array to return the granted cas session handle. * * @return true if there is CAS session granted. */ boolean requestCasSession(in CasSessionRequest request, out int[] sessionResourceId); boolean requestCasSession(in CasSessionRequest request, out int[] casSessionHandle); /* * This API is used by the Tuner framework to request an available Lnb from the TunerHAL. Loading Loading @@ -276,7 +276,7 @@ interface ITunerResourceManager { * * <p>Client must call this whenever it releases a descrambler. * * @param demuxHandle the handle of the released Tuner Descrambler. * @param descramblerHandle the handle of the released Tuner Descrambler. * @param clientId the id of the client that is releasing the descrambler. */ void releaseDescrambler(in int descramblerHandle, int clientId); Loading @@ -288,10 +288,10 @@ interface ITunerResourceManager { * * <p><strong>Note:</strong> {@link #updateCasInfo(int, int)} must be called before this release. * * @param sessionResourceId the id of the released CAS session. * @param casSessionHandle the handle of the released CAS session. * @param clientId the id of the client that is releasing the cas session. */ void releaseCasSession(in int sessionResourceId, int clientId); void releaseCasSession(in int casSessionHandle, int clientId); /* * Notifies the TRM that the Lnb with the given handle was released. Loading
media/java/android/media/tv/tunerresourcemanager/TunerResourceManager.java +7 −8 Original line number Diff line number Diff line Loading @@ -362,17 +362,16 @@ public class TunerResourceManager { * request. * * @param request {@link CasSessionRequest} information of the current request. * @param sessionResourceId a one-element array to return the granted cas session id. * If no CAS granted, this will return * {@link #INVALID_CAS_SESSION_RESOURCE_ID}. * @param casSessionHandle a one-element array to return the granted cas session handel. * If no CAS granted, this will return {@link #INVALID_RESOURCE_HANDLE}. * * @return true if there is CAS session granted. */ public boolean requestCasSession(@NonNull CasSessionRequest request, @NonNull int[] sessionResourceId) { @NonNull int[] casSessionHandle) { boolean result = false; try { result = mService.requestCasSession(request, sessionResourceId); result = mService.requestCasSession(request, casSessionHandle); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading Loading @@ -471,12 +470,12 @@ public class TunerResourceManager { * <p><strong>Note:</strong> {@link #updateCasInfo(int, int)} must be called before this * release. * * @param sessionResourceId the id of the released CAS session. * @param casSessionHandle the handle of the released CAS session. * @param clientId the id of the client that is releasing the cas session. */ public void releaseCasSession(int sessionResourceId, int clientId) { public void releaseCasSession(int casSessionHandle, int clientId) { try { mService.releaseCasSession(sessionResourceId, clientId); mService.releaseCasSession(casSessionHandle, clientId); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } Loading
services/core/java/com/android/server/tv/tunerresourcemanager/CasResource.java 0 → 100644 +152 −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 com.android.server.tv.tunerresourcemanager; import java.util.HashMap; import java.util.Map; import java.util.Set; /** * A Cas resource object used by the Tuner Resource Manager to record the cas * information. * * @hide */ public final class CasResource { private final int mSystemId; private int mMaxSessionNum; private int mAvailableSessionNum; /** * The owner clients' ids when part of the Cas is occupied. */ private Map<Integer, Integer> mOwnerClientIdsToSessionNum = new HashMap<>(); private CasResource(Builder builder) { this.mSystemId = builder.mSystemId; this.mMaxSessionNum = builder.mMaxSessionNum; this.mAvailableSessionNum = builder.mMaxSessionNum; } public int getSystemId() { return mSystemId; } public int getMaxSessionNum() { return mMaxSessionNum; } public int getUsedSessionNum() { return (mMaxSessionNum - mAvailableSessionNum); } public boolean isFullyUsed() { return mAvailableSessionNum == 0; } /** * Update max session number. * * @param maxSessionNum the new max session num. */ public void updateMaxSessionNum(int maxSessionNum) { mAvailableSessionNum = Math.max( 0, mAvailableSessionNum + (maxSessionNum - mMaxSessionNum)); mMaxSessionNum = maxSessionNum; } /** * Set an owner for the cas * * @param ownerId the client id of the owner. */ public void setOwner(int ownerId) { int sessionNum = mOwnerClientIdsToSessionNum.get(ownerId) == null ? 1 : (mOwnerClientIdsToSessionNum.get(ownerId) + 1); mOwnerClientIdsToSessionNum.put(ownerId, sessionNum); mAvailableSessionNum--; } /** * Remove an owner of the Cas. * * @param ownerId the removing client id of the owner. */ public void removeOwner(int ownerId) { mAvailableSessionNum += mOwnerClientIdsToSessionNum.get(ownerId); mOwnerClientIdsToSessionNum.remove(ownerId); } public Set<Integer> getOwnerClientIds() { return mOwnerClientIdsToSessionNum.keySet(); } @Override public String toString() { return "CasResource[systemId=" + this.mSystemId + ", isFullyUsed=" + (this.mAvailableSessionNum == 0) + ", maxSessionNum=" + this.mMaxSessionNum + ", ownerClients=" + ownersMapToString() + "]"; } /** * Builder class for {@link CasResource}. */ public static class Builder { private int mSystemId; private int mMaxSessionNum; Builder(int systemId) { this.mSystemId = systemId; } /** * Builder for {@link CasResource}. * * @param maxSessionNum the max session num the current Cas has. */ public Builder maxSessionNum(int maxSessionNum) { this.mMaxSessionNum = maxSessionNum; return this; } /** * Build a {@link CasResource}. * * @return {@link CasResource}. */ public CasResource build() { CasResource cas = new CasResource(this); return cas; } } private String ownersMapToString() { StringBuilder string = new StringBuilder("{"); for (int clienId : mOwnerClientIdsToSessionNum.keySet()) { string.append(" clientId=") .append(clienId) .append(", owns session num=") .append(mOwnerClientIdsToSessionNum.get(clienId)) .append(","); } return string.append("}").toString(); } }
services/core/java/com/android/server/tv/tunerresourcemanager/ClientProfile.java +27 −1 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import java.util.Set; public final class ClientProfile { public static final int INVALID_GROUP_ID = -1; public static final int INVALID_RESOURCE_ID = -1; /** * Client id sent to the client when registering with Loading Loading @@ -56,7 +57,6 @@ public final class ClientProfile { * also lose their resources. */ private int mGroupId = INVALID_GROUP_ID; /** * Optional nice value for TRM to reduce client’s priority. */ Loading @@ -72,6 +72,11 @@ public final class ClientProfile { */ private Set<Integer> mUsingLnbIds = new HashSet<>(); /** * List of the Cas system ids that are used by the current client. */ private int mUsingCasSystemId = INVALID_RESOURCE_ID; /** * Optional arbitrary priority value given by the client. * Loading Loading @@ -171,12 +176,33 @@ public final class ClientProfile { mUsingLnbIds.remove(lnbId); } /** * Set when the client starts to use a Cas system. * * @param casSystemId cas being used. */ public void useCas(int casSystemId) { mUsingCasSystemId = casSystemId; } public int getInUseCasSystemId() { return mUsingCasSystemId; } /** * Called when the client released a Cas System. */ public void releaseCas() { mUsingCasSystemId = INVALID_RESOURCE_ID; } /** * Called to reclaim all the resources being used by the current client. */ public void reclaimAllResources() { mUsingFrontendIds.clear(); mUsingLnbIds.clear(); mUsingCasSystemId = INVALID_RESOURCE_ID; } @Override Loading