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

Commit 25827471 authored by Chong Zhang's avatar Chong Zhang Committed by Android (Google) Code Review
Browse files

Merge "Retrieve CA_Descriptor private data for scrambled stream"

parents 33ac9a43 2773f71a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -24465,6 +24465,7 @@ package android.media {
  }
  public static final class MediaExtractor.CasInfo {
    method public byte[] getPrivateData();
    method public android.media.MediaCas.Session getSession();
    method public int getSystemId();
  }
+32 −3
Original line number Diff line number Diff line
@@ -272,10 +272,12 @@ final public class MediaExtractor {
    public static final class CasInfo {
        private final int mSystemId;
        private final MediaCas.Session mSession;
        private final byte[] mPrivateData;

        CasInfo(int systemId, @Nullable MediaCas.Session session) {
        CasInfo(int systemId, @Nullable MediaCas.Session session, @Nullable byte[] privateData) {
            mSystemId = systemId;
            mSession = session;
            mPrivateData = privateData;
        }

        /**
@@ -287,11 +289,31 @@ final public class MediaExtractor {
            return mSystemId;
        }

        /**
         * Retrieves the private data in the CA_Descriptor associated with a track.
         * Some CAS systems may need this to initialize the CAS plugin object. This
         * private data can only be retrieved before a valid {@link MediaCas} object
         * is set on the extractor.
         * <p>
         * @see MediaExtractor#setMediaCas
         * <p>
         * @return a byte array containing the private data. A null return value
         *         indicates that the private data is unavailable. An empty array,
         *         on the other hand, indicates that the private data is empty
         *         (zero in length).
         */
        @Nullable
        public byte[] getPrivateData() {
            return mPrivateData;
        }

        /**
         * Retrieves the {@link MediaCas.Session} associated with a track. The
         * session is needed to initialize a descrambler in order to decode the
         * scrambled track.
         * scrambled track. The session object can only be retrieved after a valid
         * {@link MediaCas} object is set on the extractor.
         * <p>
         * @see MediaExtractor#setMediaCas
         * @see MediaDescrambler#setMediaCasSession
         * <p>
         * @return a {@link MediaCas.Session} object associated with a track.
@@ -321,6 +343,13 @@ final public class MediaExtractor {
        if (formatMap.containsKey(MediaFormat.KEY_CA_SYSTEM_ID)) {
            int systemId = ((Integer)formatMap.get(MediaFormat.KEY_CA_SYSTEM_ID)).intValue();
            MediaCas.Session session = null;
            byte[] privateData = null;
            if (formatMap.containsKey(MediaFormat.KEY_CA_PRIVATE_DATA)) {
                ByteBuffer buf = (ByteBuffer) formatMap.get(MediaFormat.KEY_CA_PRIVATE_DATA);
                buf.rewind();
                privateData = new byte[buf.remaining()];
                buf.get(privateData);
            }
            if (mMediaCas != null && formatMap.containsKey(MediaFormat.KEY_CA_SESSION_ID)) {
                ByteBuffer buf = (ByteBuffer) formatMap.get(MediaFormat.KEY_CA_SESSION_ID);
                buf.rewind();
@@ -328,7 +357,7 @@ final public class MediaExtractor {
                buf.get(sessionId);
                session = mMediaCas.createFromSessionId(toByteArray(sessionId));
            }
            return new CasInfo(systemId, session);
            return new CasInfo(systemId, session, privateData);
        }
        return null;
    }
+14 −2
Original line number Diff line number Diff line
@@ -919,7 +919,7 @@ public final class MediaFormat {
     * a media track.
     * <p>
     * This key is set by {@link MediaExtractor} if the track is scrambled with a conditional
     * access system.
     * access system, regardless of the presence of a valid {@link MediaCas} object.
     * <p>
     * The associated value is an integer.
     * @hide
@@ -930,13 +930,25 @@ public final class MediaFormat {
     * A key describing the {@link MediaCas.Session} object associated with a media track.
     * <p>
     * This key is set by {@link MediaExtractor} if the track is scrambled with a conditional
     * access system.
     * access system, after it receives a valid {@link MediaCas} object.
     * <p>
     * The associated value is a ByteBuffer.
     * @hide
     */
    public static final String KEY_CA_SESSION_ID = "ca-session-id";


    /**
     * A key describing the private data in the CA_descriptor associated with a media track.
     * <p>
     * This key is set by {@link MediaExtractor} if the track is scrambled with a conditional
     * access system, before it receives a valid {@link MediaCas} object.
     * <p>
     * The associated value is a ByteBuffer.
     * @hide
     */
    public static final String KEY_CA_PRIVATE_DATA = "ca-private-data";

    /* package private */ MediaFormat(Map<String, Object> map) {
        mMap = map;
    }