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

Commit e4edcab4 authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Add parameter for including supplemental data

Bug: 154120292
Test: atest CtsMediaParserTestCases
Change-Id: Ic374df6863558bc4432175b0483fabe855423d8c
parent f633705a
Loading
Loading
Loading
Loading
+45 −4
Original line number Original line Diff line number Diff line
@@ -467,7 +467,24 @@ public final class MediaParser {
    public @interface SampleFlags {}
    public @interface SampleFlags {}
    /** Indicates that the sample holds a synchronization sample. */
    /** Indicates that the sample holds a synchronization sample. */
    public static final int SAMPLE_FLAG_KEY_FRAME = MediaCodec.BUFFER_FLAG_KEY_FRAME;
    public static final int SAMPLE_FLAG_KEY_FRAME = MediaCodec.BUFFER_FLAG_KEY_FRAME;
    /** Indicates that the sample has supplemental data. */
    /**
     * Indicates that the sample has supplemental data.
     *
     * <p>Samples will not have this flag set unless the {@code
     * "android.media.mediaparser.includeSupplementalData"} parameter is set to {@code true} via
     * {@link #setParameter}.
     *
     * <p>Samples with supplemental data have the following sample data format:
     *
     * <ul>
     *   <li>If the {@code "android.media.mediaparser.inBandCryptoInfo"} parameter is set, all
     *       encryption information.
     *   <li>(4 bytes) {@code sample_data_size}: The size of the actual sample data, not including
     *       supplemental data or encryption information.
     *   <li>({@code sample_data_size} bytes): The media sample data.
     *   <li>(remaining bytes) The supplemental data.
     * </ul>
     */
    public static final int SAMPLE_FLAG_HAS_SUPPLEMENTAL_DATA = 1 << 28;
    public static final int SAMPLE_FLAG_HAS_SUPPLEMENTAL_DATA = 1 << 28;
    /** Indicates that the sample is known to contain the last media sample of the stream. */
    /** Indicates that the sample is known to contain the last media sample of the stream. */
    public static final int SAMPLE_FLAG_LAST_SAMPLE = 1 << 29;
    public static final int SAMPLE_FLAG_LAST_SAMPLE = 1 << 29;
@@ -578,7 +595,9 @@ public final class MediaParser {
                PARAMETER_TS_IGNORE_AVC_STREAM,
                PARAMETER_TS_IGNORE_AVC_STREAM,
                PARAMETER_TS_IGNORE_SPLICE_INFO_STREAM,
                PARAMETER_TS_IGNORE_SPLICE_INFO_STREAM,
                PARAMETER_TS_DETECT_ACCESS_UNITS,
                PARAMETER_TS_DETECT_ACCESS_UNITS,
                PARAMETER_TS_ENABLE_HDMV_DTS_AUDIO_STREAMS
                PARAMETER_TS_ENABLE_HDMV_DTS_AUDIO_STREAMS,
                PARAMETER_IN_BAND_CRYPTO_INFO,
                PARAMETER_INCLUDE_SUPPLEMENTAL_DATA
            })
            })
    public @interface ParameterName {}
    public @interface ParameterName {}


@@ -740,6 +759,16 @@ public final class MediaParser {
    public static final String PARAMETER_IN_BAND_CRYPTO_INFO =
    public static final String PARAMETER_IN_BAND_CRYPTO_INFO =
            "android.media.mediaparser.inBandCryptoInfo";
            "android.media.mediaparser.inBandCryptoInfo";


    /**
     * Sets whether supplemental data should be included as part of the sample data. {@code boolean}
     * expected. Default value is {@code false}. See {@link #SAMPLE_FLAG_HAS_SUPPLEMENTAL_DATA} for
     * information about the sample data format.
     *
     * @hide
     */
    public static final String PARAMETER_INCLUDE_SUPPLEMENTAL_DATA =
            "android.media.mediaparser.includeSupplementalData";

    // Private constants.
    // Private constants.


    private static final String TAG = "MediaParser";
    private static final String TAG = "MediaParser";
@@ -899,6 +928,7 @@ public final class MediaParser {
    private final ParsableByteArrayAdapter mScratchParsableByteArrayAdapter;
    private final ParsableByteArrayAdapter mScratchParsableByteArrayAdapter;
    @Nullable private final Constructor<DrmInitData.SchemeInitData> mSchemeInitDataConstructor;
    @Nullable private final Constructor<DrmInitData.SchemeInitData> mSchemeInitDataConstructor;
    private boolean mInBandCryptoInfo;
    private boolean mInBandCryptoInfo;
    private boolean mIncludeSupplementalData;
    private String mParserName;
    private String mParserName;
    private Extractor mExtractor;
    private Extractor mExtractor;
    private ExtractorInput mExtractorInput;
    private ExtractorInput mExtractorInput;
@@ -949,6 +979,9 @@ public final class MediaParser {
        if (PARAMETER_IN_BAND_CRYPTO_INFO.equals(parameterName)) {
        if (PARAMETER_IN_BAND_CRYPTO_INFO.equals(parameterName)) {
            mInBandCryptoInfo = (boolean) value;
            mInBandCryptoInfo = (boolean) value;
        }
        }
        if (PARAMETER_INCLUDE_SUPPLEMENTAL_DATA.equals(parameterName)) {
            mIncludeSupplementalData = (boolean) value;
        }
        mParserParameters.put(parameterName, value);
        mParserParameters.put(parameterName, value);
        return this;
        return this;
    }
    }
@@ -1330,6 +1363,7 @@ public final class MediaParser {
        private int mEncryptionVectorSize;
        private int mEncryptionVectorSize;
        private boolean mHasSubsampleEncryptionData;
        private boolean mHasSubsampleEncryptionData;
        private CryptoInfo.Pattern mEncryptionPattern;
        private CryptoInfo.Pattern mEncryptionPattern;
        private int mSkippedSupplementalDataBytes;


        private TrackOutputAdapter(int trackIndex) {
        private TrackOutputAdapter(int trackIndex) {
            mTrackIndex = trackIndex;
            mTrackIndex = trackIndex;
@@ -1419,6 +1453,10 @@ public final class MediaParser {
                            throw new IllegalStateException();
                            throw new IllegalStateException();
                    }
                    }
                }
                }
            } else if (sampleDataPart == SAMPLE_DATA_PART_SUPPLEMENTAL
                    && !mIncludeSupplementalData) {
                mSkippedSupplementalDataBytes += length;
                data.skipBytes(length);
            } else {
            } else {
                outputSampleData(data, length);
                outputSampleData(data, length);
            }
            }
@@ -1427,6 +1465,8 @@ public final class MediaParser {
        @Override
        @Override
        public void sampleMetadata(
        public void sampleMetadata(
                long timeUs, int flags, int size, int offset, @Nullable CryptoData cryptoData) {
                long timeUs, int flags, int size, int offset, @Nullable CryptoData cryptoData) {
            size -= mSkippedSupplementalDataBytes;
            mSkippedSupplementalDataBytes = 0;
            mOutputConsumer.onSampleCompleted(
            mOutputConsumer.onSampleCompleted(
                    mTrackIndex,
                    mTrackIndex,
                    timeUs,
                    timeUs,
@@ -1686,13 +1726,13 @@ public final class MediaParser {
        }
        }
    }
    }


    private static int getMediaParserFlags(int flags) {
    private int getMediaParserFlags(int flags) {
        @SampleFlags int result = 0;
        @SampleFlags int result = 0;
        result |= (flags & C.BUFFER_FLAG_ENCRYPTED) != 0 ? SAMPLE_FLAG_ENCRYPTED : 0;
        result |= (flags & C.BUFFER_FLAG_ENCRYPTED) != 0 ? SAMPLE_FLAG_ENCRYPTED : 0;
        result |= (flags & C.BUFFER_FLAG_KEY_FRAME) != 0 ? SAMPLE_FLAG_KEY_FRAME : 0;
        result |= (flags & C.BUFFER_FLAG_KEY_FRAME) != 0 ? SAMPLE_FLAG_KEY_FRAME : 0;
        result |= (flags & C.BUFFER_FLAG_DECODE_ONLY) != 0 ? SAMPLE_FLAG_DECODE_ONLY : 0;
        result |= (flags & C.BUFFER_FLAG_DECODE_ONLY) != 0 ? SAMPLE_FLAG_DECODE_ONLY : 0;
        result |=
        result |=
                (flags & C.BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA) != 0
                (flags & C.BUFFER_FLAG_HAS_SUPPLEMENTAL_DATA) != 0 && mIncludeSupplementalData
                        ? SAMPLE_FLAG_HAS_SUPPLEMENTAL_DATA
                        ? SAMPLE_FLAG_HAS_SUPPLEMENTAL_DATA
                        : 0;
                        : 0;
        result |= (flags & C.BUFFER_FLAG_LAST_SAMPLE) != 0 ? SAMPLE_FLAG_LAST_SAMPLE : 0;
        result |= (flags & C.BUFFER_FLAG_LAST_SAMPLE) != 0 ? SAMPLE_FLAG_LAST_SAMPLE : 0;
@@ -1755,6 +1795,7 @@ public final class MediaParser {
        expectedTypeByParameterName.put(PARAMETER_TS_DETECT_ACCESS_UNITS, Boolean.class);
        expectedTypeByParameterName.put(PARAMETER_TS_DETECT_ACCESS_UNITS, Boolean.class);
        expectedTypeByParameterName.put(PARAMETER_TS_ENABLE_HDMV_DTS_AUDIO_STREAMS, Boolean.class);
        expectedTypeByParameterName.put(PARAMETER_TS_ENABLE_HDMV_DTS_AUDIO_STREAMS, Boolean.class);
        expectedTypeByParameterName.put(PARAMETER_IN_BAND_CRYPTO_INFO, Boolean.class);
        expectedTypeByParameterName.put(PARAMETER_IN_BAND_CRYPTO_INFO, Boolean.class);
        expectedTypeByParameterName.put(PARAMETER_INCLUDE_SUPPLEMENTAL_DATA, Boolean.class);
        EXPECTED_TYPE_BY_PARAMETER_NAME = Collections.unmodifiableMap(expectedTypeByParameterName);
        EXPECTED_TYPE_BY_PARAMETER_NAME = Collections.unmodifiableMap(expectedTypeByParameterName);
    }
    }
}
}