Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a78c1cc9 authored by Chong Zhang's avatar Chong Zhang
Browse files

MediaCas: combine openSession methods

Combine the two openSession methods into one that doesn't take any
arguments. This gives the client more flexibility on creating
sessions efficiently. They can better decide whether to share one
session for multiple streams, or create one session per stream.

bug: 22804304

Change-Id: I9634f4dd4fc437229068103b54555cc28a818937
parent bc7aae4f
Loading
Loading
Loading
Loading
+4 −25
Original line number Diff line number Diff line
@@ -113,36 +113,15 @@ Status CasImpl::setPrivateData(const CasData& pvtData) {
    return getBinderStatus(holder->get()->setPrivateData(pvtData));
}

Status CasImpl::openSession(int32_t program_number, CasSessionId* sessionId) {
    ALOGV("openSession: program_number=%d", program_number);
Status CasImpl::openSession(CasSessionId* sessionId) {
    ALOGV("openSession");
    sp<PluginHolder> holder = mPluginHolder;
    if (holder == NULL) {
        return getBinderStatus(INVALID_OPERATION);
    }
    status_t err = holder->get()->openSession(program_number, sessionId);
    status_t err = holder->get()->openSession(sessionId);

    ALOGV("openSession: session opened for program_number=%d, sessionId=%s",
            program_number, sessionIdToString(*sessionId).string());

    return getBinderStatus(err);
}

Status CasImpl::openSessionForStream(
        int32_t program_number,
        int32_t elementary_PID,
        CasSessionId* sessionId) {
    ALOGV("openSession: program_number=%d, elementary_PID=%d",
            program_number, elementary_PID);
    sp<PluginHolder> holder = mPluginHolder;
    if (holder == NULL) {
        return getBinderStatus(INVALID_OPERATION);
    }
    status_t err = holder->get()->openSession(
            program_number, elementary_PID, sessionId);

    ALOGV("openSession: session opened for "
            "program_number=%d, elementary_PID=%d, sessionId=%s",
            program_number, elementary_PID,
    ALOGV("openSession: session opened, sessionId=%s",
            sessionIdToString(*sessionId).string());

    return getBinderStatus(err);
+1 −2
Original line number Diff line number Diff line
@@ -21,8 +21,7 @@ import android.media.MediaCas;
/** @hide */
interface ICas {
    void setPrivateData(in byte[] pvtData);
    byte[] openSession(int program_number);
    byte[] openSessionForStream(int program_number, int elementary_PID);
    byte[] openSession();
    void closeSession(in byte[] sessionId);
    void setSessionPrivateData(in byte[] sessionId, in byte[] pvtData);
    void processEcm(in byte[] sessionId, in MediaCas.ParcelableCasData ecm);
+3 −16
Original line number Diff line number Diff line
@@ -110,23 +110,10 @@ static String8 sessionIdToString(const std::vector<uint8_t> &array) {
    return result;
}

status_t ClearKeyCasPlugin::openSession(
        uint16_t program_number, CasSessionId* sessionId) {
    ALOGV("openSession: program_number=%u", program_number);
status_t ClearKeyCasPlugin::openSession(CasSessionId* sessionId) {
    ALOGV("openSession");

    return ClearKeySessionLibrary::get()->addSession(
            this, program_number, 0, sessionId);
}

status_t ClearKeyCasPlugin::openSession(
        uint16_t program_number,
        uint16_t elementary_PID,
        CasSessionId *sessionId) {
    ALOGV("openSession: program_number=%u, elementary_PID=%u",
            program_number, elementary_PID);

    return ClearKeySessionLibrary::get()->addSession(
            this, program_number, elementary_PID, sessionId);
    return ClearKeySessionLibrary::get()->addSession(this, sessionId);
}

status_t ClearKeyCasPlugin::closeSession(const CasSessionId &sessionId) {
+1 −7
Original line number Diff line number Diff line
@@ -68,13 +68,7 @@ public:
    virtual status_t setPrivateData(
            const CasData &data) override;

    virtual status_t openSession(
            uint16_t program_number, CasSessionId *sessionId) override;

    virtual status_t openSession(
            uint16_t program_number,
            uint16_t elementary_PID,
            CasSessionId *sessionId) override;
    virtual status_t openSession(CasSessionId *sessionId) override;

    virtual status_t closeSession(
            const CasSessionId &sessionId) override;
+8 −39
Original line number Diff line number Diff line
@@ -29,29 +29,14 @@ namespace clearkeycas {
Mutex ClearKeySessionLibrary::sSingletonLock;
ClearKeySessionLibrary* ClearKeySessionLibrary::sSingleton = NULL;

inline bool operator < (
        const SessionInfo& lhs, const SessionInfo& rhs) {
    if (lhs.plugin < rhs.plugin) return true;
    else if (lhs.plugin > rhs.plugin) return false;

    if (lhs.program_number < rhs.program_number) return true;
    else if (lhs.program_number > rhs.program_number) return false;

    return lhs.elementary_PID < rhs.elementary_PID;
}

ClearKeyCasSession::ClearKeyCasSession(const SessionInfo &info)
    : mSessionInfo(info) {
ClearKeyCasSession::ClearKeyCasSession(CasPlugin *plugin)
    : mPlugin(plugin) {
    mKeyInfo[0].valid = mKeyInfo[1].valid = false;
}

ClearKeyCasSession::~ClearKeyCasSession() {
}

const SessionInfo& ClearKeyCasSession::getSessionInfo() const {
    return mSessionInfo;
}

ClearKeySessionLibrary* ClearKeySessionLibrary::get() {
    Mutex::Autolock lock(sSingletonLock);

@@ -66,24 +51,12 @@ ClearKeySessionLibrary* ClearKeySessionLibrary::get() {
ClearKeySessionLibrary::ClearKeySessionLibrary() : mNextSessionId(1) {}

status_t ClearKeySessionLibrary::addSession(
        CasPlugin *plugin,
        uint16_t program_number,
        uint16_t elementary_PID,
        CasSessionId *sessionId) {
        CasPlugin *plugin, CasSessionId *sessionId) {
    CHECK(sessionId);

    Mutex::Autolock lock(mSessionsLock);

    SessionInfo info = {plugin, program_number, elementary_PID};
    ssize_t index = mSessionInfoToIDMap.indexOfKey(info);
    if (index >= 0) {
        ALOGW("Session already exists: program_number=%u, elementary_PID=%u",
                program_number, elementary_PID);
        *sessionId = mSessionInfoToIDMap[index];
        return OK;
    }

    sp<ClearKeyCasSession> session = new ClearKeyCasSession(info);
    sp<ClearKeyCasSession> session = new ClearKeyCasSession(plugin);

    uint8_t *byteArray = (uint8_t *) &mNextSessionId;
    sessionId->push_back(byteArray[3]);
@@ -92,7 +65,6 @@ status_t ClearKeySessionLibrary::addSession(
    sessionId->push_back(byteArray[0]);
    mNextSessionId++;

    mSessionInfoToIDMap.add(info, *sessionId);
    mIDToSessionMap.add(*sessionId, session);
    return OK;
}
@@ -117,19 +89,16 @@ void ClearKeySessionLibrary::destroySession(const CasSessionId& sessionId) {
    }

    sp<ClearKeyCasSession> session = mIDToSessionMap.valueAt(index);
    mSessionInfoToIDMap.removeItem(session->getSessionInfo());
    mIDToSessionMap.removeItemsAt(index);
}

void ClearKeySessionLibrary::destroyPlugin(CasPlugin *plugin) {
    Mutex::Autolock lock(mSessionsLock);

    for (ssize_t index = mSessionInfoToIDMap.size() - 1; index >= 0; index--) {
        const SessionInfo &info = mSessionInfoToIDMap.keyAt(index);
        if (info.plugin == plugin) {
            const CasSessionId &id = mSessionInfoToIDMap.valueAt(index);
            mIDToSessionMap.removeItem(id);
            mSessionInfoToIDMap.removeItemsAt(index);
    for (ssize_t index = mIDToSessionMap.size() - 1; index >= 0; index--) {
        sp<ClearKeyCasSession> session = mIDToSessionMap.valueAt(index);
        if (session->getPlugin() == plugin) {
            mIDToSessionMap.removeItemsAt(index);
        }
    }
}
Loading