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

Commit 2551c63d authored by Hangyu Kuang's avatar Hangyu Kuang Committed by Android (Google) Code Review
Browse files

Merge "transcoding: Add new API for setting FileDescriptor."

parents 0926f198 40f3dcb5
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -14,8 +14,10 @@ package android.media {
  public static final class MediaTranscodeManager.TranscodingRequest {
    method public int getClientPid();
    method public int getClientUid();
    method @Nullable public android.os.ParcelFileDescriptor getDestinationFileDescriptor();
    method @NonNull public android.net.Uri getDestinationUri();
    method public int getPriority();
    method @Nullable public android.os.ParcelFileDescriptor getSourceFileDescriptor();
    method @NonNull public android.net.Uri getSourceUri();
    method public int getType();
    method @Nullable public android.media.MediaFormat getVideoTrackFormat();
@@ -26,8 +28,10 @@ package android.media {
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest build();
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest.Builder setClientPid(int);
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest.Builder setClientUid(int);
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest.Builder setDestinationFileDescriptor(@NonNull android.os.ParcelFileDescriptor);
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest.Builder setDestinationUri(@NonNull android.net.Uri);
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest.Builder setPriority(int);
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest.Builder setSourceFileDescriptor(@NonNull android.os.ParcelFileDescriptor);
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest.Builder setSourceUri(@NonNull android.net.Uri);
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest.Builder setType(int);
    method @NonNull public android.media.MediaTranscodeManager.TranscodingRequest.Builder setVideoTrackFormat(@NonNull android.media.MediaFormat);
+82 −1
Original line number Diff line number Diff line
@@ -505,6 +505,12 @@ public final class MediaTranscodeManager {
        /** Uri of the destination media file. */
        private @NonNull Uri mDestinationUri;

        /** FileDescriptor of the source media file. */
        private @Nullable ParcelFileDescriptor mSourceFileDescriptor;

        /** FileDescriptor of the destination media file. */
        private @Nullable ParcelFileDescriptor mDestinationFileDescriptor;

        /**
         *  The UID of the client that the TranscodingRequest is for. Only privileged caller could
         *  set this Uid as only they could do the transcoding on behalf of the client.
@@ -554,7 +560,9 @@ public final class MediaTranscodeManager {

        private TranscodingRequest(Builder b) {
            mSourceUri = b.mSourceUri;
            mSourceFileDescriptor = b.mSourceFileDescriptor;
            mDestinationUri = b.mDestinationUri;
            mDestinationFileDescriptor = b.mDestinationFileDescriptor;
            mClientUid = b.mClientUid;
            mClientPid = b.mClientPid;
            mPriority = b.mPriority;
@@ -577,6 +585,15 @@ public final class MediaTranscodeManager {
            return mSourceUri;
        }

        /**
         * Return source file descriptor of the transcoding.
         * This will be null if client has not provided it.
         */
        @Nullable
        public ParcelFileDescriptor getSourceFileDescriptor() {
            return mSourceFileDescriptor;
        }

        /** Return the UID of the client that this request is for. -1 means not available. */
        public int getClientUid() {
            return mClientUid;
@@ -593,6 +610,15 @@ public final class MediaTranscodeManager {
            return mDestinationUri;
        }

        /**
         * Return destination file descriptor of the transcoding.
         * This will be null if client has not provided it.
         */
        @Nullable
        public ParcelFileDescriptor getDestinationFileDescriptor() {
            return mDestinationFileDescriptor;
        }

        /** Return priority of the transcoding. */
        @TranscodingPriority
        public int getPriority() {
@@ -623,7 +649,9 @@ public final class MediaTranscodeManager {
            parcel.priority = mPriority;
            parcel.transcodingType = mType;
            parcel.sourceFilePath = mSourceUri.toString();
            parcel.sourceFd = mSourceFileDescriptor;
            parcel.destinationFilePath = mDestinationUri.toString();
            parcel.destinationFd = mDestinationFileDescriptor;
            parcel.clientUid = mClientUid;
            parcel.clientPid = mClientPid;
            if (mClientUid < 0) {
@@ -713,6 +741,8 @@ public final class MediaTranscodeManager {
        public static final class Builder {
            private @NonNull Uri mSourceUri;
            private @NonNull Uri mDestinationUri;
            private @Nullable ParcelFileDescriptor mSourceFileDescriptor = null;
            private @Nullable ParcelFileDescriptor mDestinationFileDescriptor = null;
            private int mClientUid = -1;
            private int mClientPid = -1;
            private @TranscodingType int mType = TRANSCODING_TYPE_UNKNOWN;
@@ -725,11 +755,14 @@ public final class MediaTranscodeManager {
            /**
             * Specifies the uri of source media file.
             *
             * Client must set the source Uri. If client also provides the source fileDescriptor
             * through is provided by {@link #setSourceFileDescriptor(ParcelFileDescriptor)},
             * TranscodingSession will use the fd instead of calling back to the client to open the
             * sourceUri.
             * @param sourceUri Content uri for the source media file.
             * @return The same builder instance.
             * @throws IllegalArgumentException if Uri is null or empty.
             */
            // TODO(hkuang): Add documentation on how the app could generate the correct Uri.
            @NonNull
            public Builder setSourceUri(@NonNull Uri sourceUri) {
                if (sourceUri == null || Uri.EMPTY.equals(sourceUri)) {
@@ -740,9 +773,34 @@ public final class MediaTranscodeManager {
                return this;
            }

            /**
             * Specifies the fileDescriptor opened from the source media file.
             *
             * This call is optional. If the source fileDescriptor is provided, TranscodingSession
             * will use it directly instead of opening the uri from {@link #setSourceUri(Uri)}. It
             * is client's responsibility to make sure the fileDescriptor is opened from the source
             * uri.
             * @param fileDescriptor a {@link ParcelFileDescriptor} opened from source media file.
             * @return The same builder instance.
             * @throws IllegalArgumentException if fileDescriptor is invalid.
             */
            @NonNull
            public Builder setSourceFileDescriptor(@NonNull ParcelFileDescriptor fileDescriptor) {
                if (fileDescriptor == null || fileDescriptor.getFd() < 0) {
                    throw new IllegalArgumentException(
                            "Invalid source descriptor.");
                }
                mSourceFileDescriptor = fileDescriptor;
                return this;
            }

            /**
             * Specifies the uri of the destination media file.
             *
             * Client must set the destination Uri. If client also provides the destination
             * fileDescriptor through {@link #setDestinationFileDescriptor(ParcelFileDescriptor)},
             * TranscodingSession will use the fd instead of calling back to the client to open the
             * destinationUri.
             * @param destinationUri Content uri for the destination media file.
             * @return The same builder instance.
             * @throws IllegalArgumentException if Uri is null or empty.
@@ -757,6 +815,29 @@ public final class MediaTranscodeManager {
                return this;
            }

            /**
             * Specifies the fileDescriptor opened from the destination media file.
             *
             * This call is optional. If the destination fileDescriptor is provided,
             * TranscodingSession will use it directly instead of opening the uri from
             * {@link #setDestinationUri(Uri)} upon transcoding starts. It is client's
             * responsibility to make sure the fileDescriptor is opened from the destination uri.
             * @param fileDescriptor a {@link ParcelFileDescriptor} opened from destination media
             *                       file.
             * @return The same builder instance.
             * @throws IllegalArgumentException if fileDescriptor is invalid.
             */
            @NonNull
            public Builder setDestinationFileDescriptor(
                    @NonNull ParcelFileDescriptor fileDescriptor) {
                if (fileDescriptor == null || fileDescriptor.getFd() < 0) {
                    throw new IllegalArgumentException(
                            "Invalid destination descriptor.");
                }
                mDestinationFileDescriptor = fileDescriptor;
                return this;
            }

            /**
             * Specify the UID of the client that this request is for.
             * @param uid client Uid.