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

Commit 56c33e35 authored by Ray Chin's avatar Ray Chin
Browse files

Support reassembling fragmented media events

API-Coverage-Bug: 367917024
Flag: android.media.tv.flags.tuner_w_apis
Bug: 281787325
Test: atest CtsTvTestCases on cf_x86_tv-staging-userdebug
Change-Id: I49aa50bf2d2a8ad0118ef817b5416ad1532db670
parent 887785ab
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -8450,11 +8450,14 @@ package android.media.tv.tuner.filter {
    method public long getAudioHandle();
    method @NonNull public java.util.List<android.media.AudioPresentation> getAudioPresentations();
    method public long getAvDataId();
    method @FlaggedApi("android.media.tv.flags.tuner_w_apis") public int getDataGroupId();
    method public long getDataLength();
    method public long getDts();
    method @Nullable public android.media.tv.tuner.filter.AudioDescriptor getExtraMetaData();
    method @FlaggedApi("android.media.tv.flags.tuner_w_apis") @IntRange(from=0) public int getIndexInDataGroup();
    method @Nullable public android.media.MediaCodec.LinearBlock getLinearBlock();
    method @IntRange(from=0) public int getMpuSequenceNumber();
    method @FlaggedApi("android.media.tv.flags.tuner_w_apis") @IntRange(from=0) public int getNumDataPieces();
    method public long getOffset();
    method public long getPts();
    method public int getScIndexMask();
+71 −1
Original line number Diff line number Diff line
@@ -17,12 +17,14 @@
package android.media.tv.tuner.filter;

import android.annotation.BytesLong;
import android.annotation.FlaggedApi;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.media.AudioPresentation;
import android.media.MediaCodec.LinearBlock;
import android.media.tv.flags.Flags;

import java.util.Collections;
import java.util.List;
@@ -57,12 +59,16 @@ public class MediaEvent extends FilterEvent {
    private final int mScIndexMask;
    private final AudioDescriptor mExtraMetaData;
    private final List<AudioPresentation> mAudioPresentations;
    private final int mNumDataPieces;
    private final int mIndexInDataGroup;
    private final int mDataGroupId;

    // This constructor is used by JNI code only
    private MediaEvent(int streamId, boolean isPtsPresent, long pts, boolean isDtsPresent, long dts,
            long dataLength, long offset, LinearBlock buffer, boolean isSecureMemory, long dataId,
            int mpuSequenceNumber, boolean isPrivateData, int scIndexMask,
            AudioDescriptor extraMetaData, List<AudioPresentation> audioPresentations) {
            AudioDescriptor extraMetaData, List<AudioPresentation> audioPresentations,
            int numDataPieces, int indexInDataGroup, int dataGroupId) {
        mStreamId = streamId;
        mIsPtsPresent = isPtsPresent;
        mPts = pts;
@@ -78,6 +84,9 @@ public class MediaEvent extends FilterEvent {
        mScIndexMask = scIndexMask;
        mExtraMetaData = extraMetaData;
        mAudioPresentations = audioPresentations;
        mNumDataPieces = numDataPieces;
        mIndexInDataGroup = indexInDataGroup;
        mDataGroupId = dataGroupId;
    }

    /**
@@ -234,6 +243,67 @@ public class MediaEvent extends FilterEvent {
        return mAudioPresentations == null ? Collections.emptyList() : mAudioPresentations;
    }

    /**
     * Gets the number of data pieces into which the original data was split.
     *
     * <p>The {@link #getNumDataPieces()}, {@link #getIndexInDataGroup()} and
     * {@link #getDataGroupId()} methods should be used together to reassemble the original data if
     * it was split into pieces. Use {@link #getLinearBlock()} to get the memory where the data
     * pieces are stored.
     *
     * @return 0 or 1 if this MediaEvent object contains the complete data; otherwise the number of
     *         pieces into which the original data was split.
     * @see #getIndexInDataGroup()
     * @see #getDataGroupId()
     * @see #getLinearBlock()
     */
    @FlaggedApi(Flags.FLAG_TUNER_W_APIS)
    @IntRange(from = 0)
    public int getNumDataPieces() {
        return mNumDataPieces;
    }

    /**
     * Gets the index of the data piece. The index in the data group indicates the order in which
     * this {@link MediaEvent}'s data piece should be reassembled. The result should be within the
     * range [0, {@link #getNumDataPieces()}).
     *
     * <p>The {@link #getNumDataPieces()}, {@link #getIndexInDataGroup()} and
     * {@link #getDataGroupId()} methods should be used together to reassemble the original data if
     * it was split into pieces. Use {@link #getLinearBlock()} to get the memory where the data
     * pieces are stored.
     *
     * @return The index in the data group.
     * @see #getNumDataPieces()
     * @see #getDataGroupId()
     * @see #getLinearBlock()
     */
    @FlaggedApi(Flags.FLAG_TUNER_W_APIS)
    @IntRange(from = 0)
    public int getIndexInDataGroup() {
        return mIndexInDataGroup;
    }

    /**
     * Gets the group ID for reassembling the complete data. {@link MediaEvent}s that have the same
     * data group ID contain different pieces of the same data. This value should be ignored if
     * {@link #getNumDataPieces()} returns 0 or 1.
     *
     * <p>The {@link #getNumDataPieces()}, {@link #getIndexInDataGroup()} and
     * {@link #getDataGroupId()} methods should be used together to reassemble the original data if
     * it was split into pieces. Use {@link #getLinearBlock()} to get the memory where the data
     * pieces are stored.
     *
     * @return The data group ID.
     * @see #getNumDataPieces()
     * @see #getIndexInDataGroup()
     * @see #getLinearBlock()
     */
    @FlaggedApi(Flags.FLAG_TUNER_W_APIS)
    public int getDataGroupId() {
        return mDataGroupId;
    }

    /**
     * Finalize the MediaEvent object.
     * @hide
+6 −2
Original line number Diff line number Diff line
@@ -686,12 +686,16 @@ void FilterClientCallbackImpl::getMediaEvent(const jobjectArray& arr, const int
    } else if (mediaEvent.scIndexMask.getTag() == DemuxFilterScIndexMask::Tag::scVvc) {
        sc = mediaEvent.scIndexMask.get<DemuxFilterScIndexMask::Tag::scVvc>();
    }
    jint numDataPieces = mediaEvent.numDataPieces;
    jint indexInDataGroup = mediaEvent.indexInDataGroup;
    jint dataGroupId = mediaEvent.dataGroupId;

    ScopedLocalRef obj(env, env->NewObject(mMediaEventClass, mMediaEventInitID, streamId,
                                           isPtsPresent, pts, isDtsPresent, dts, dataLength,
                                           offset, nullptr, isSecureMemory, avDataId,
                                           mpuSequenceNumber, isPesPrivateData, sc,
                                           audioDescriptor.get(), presentationsJObj.get()));
                                           audioDescriptor.get(), presentationsJObj.get(),
                                           numDataPieces, indexInDataGroup, dataGroupId));

    // Protect mFilterClient from being set to null.
    android::Mutex::Autolock autoLock(mLock);
@@ -1048,7 +1052,7 @@ FilterClientCallbackImpl::FilterClientCallbackImpl() {
            "<init>",
            "(IZJZJJJLandroid/media/MediaCodec$LinearBlock;"
            "ZJIZILandroid/media/tv/tuner/filter/AudioDescriptor;"
            "Ljava/util/List;)V");
            "Ljava/util/List;III)V");
    mAudioDescriptorInitID = env->GetMethodID(mAudioDescriptorClass, "<init>", "(BBCBBB)V");
    mPesEventInitID = env->GetMethodID(mPesEventClass, "<init>", "(III)V");
    mTsRecordEventInitID = env->GetMethodID(mTsRecordEventClass, "<init>", "(IIIJJI)V");