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

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

Merge "trasncoding: handle unspecified format correctly."

parents 97e2d643 66d7d0d3
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -6,9 +6,11 @@ package android.media {
    method public int describeContents();
    method public int describeContents();
    method @NonNull public java.util.List<java.lang.String> getSupportedHdrTypes();
    method @NonNull public java.util.List<java.lang.String> getSupportedHdrTypes();
    method @NonNull public java.util.List<java.lang.String> getSupportedVideoMimeTypes();
    method @NonNull public java.util.List<java.lang.String> getSupportedVideoMimeTypes();
    method public boolean isHdrTypeSupported(@NonNull String);
    method @NonNull public java.util.List<java.lang.String> getUnsupportedHdrTypes();
    method @NonNull public java.util.List<java.lang.String> getUnsupportedVideoMimeTypes();
    method public boolean isHdrTypeSupported(@NonNull String) throws android.media.ApplicationMediaCapabilities.FormatNotFoundException;
    method public boolean isSlowMotionSupported();
    method public boolean isSlowMotionSupported();
    method public boolean isVideoMimeTypeSupported(@NonNull String);
    method public boolean isVideoMimeTypeSupported(@NonNull String) throws android.media.ApplicationMediaCapabilities.FormatNotFoundException;
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.media.ApplicationMediaCapabilities> CREATOR;
    field @NonNull public static final android.os.Parcelable.Creator<android.media.ApplicationMediaCapabilities> CREATOR;
  }
  }
@@ -17,10 +19,16 @@ package android.media {
    ctor public ApplicationMediaCapabilities.Builder();
    ctor public ApplicationMediaCapabilities.Builder();
    method @NonNull public android.media.ApplicationMediaCapabilities.Builder addSupportedHdrType(@NonNull String);
    method @NonNull public android.media.ApplicationMediaCapabilities.Builder addSupportedHdrType(@NonNull String);
    method @NonNull public android.media.ApplicationMediaCapabilities.Builder addSupportedVideoMimeType(@NonNull String);
    method @NonNull public android.media.ApplicationMediaCapabilities.Builder addSupportedVideoMimeType(@NonNull String);
    method @NonNull public android.media.ApplicationMediaCapabilities.Builder addUnsupportedHdrType(@NonNull String);
    method @NonNull public android.media.ApplicationMediaCapabilities.Builder addUnsupportedVideoMimeType(@NonNull String);
    method @NonNull public android.media.ApplicationMediaCapabilities build();
    method @NonNull public android.media.ApplicationMediaCapabilities build();
    method @NonNull public android.media.ApplicationMediaCapabilities.Builder setSlowMotionSupported(boolean);
    method @NonNull public android.media.ApplicationMediaCapabilities.Builder setSlowMotionSupported(boolean);
  }
  }


  public static class ApplicationMediaCapabilities.FormatNotFoundException extends android.util.AndroidException {
    ctor public ApplicationMediaCapabilities.FormatNotFoundException(@NonNull String);
  }

  public class MediaController2 implements java.lang.AutoCloseable {
  public class MediaController2 implements java.lang.AutoCloseable {
    method public void cancelSessionCommand(@NonNull Object);
    method public void cancelSessionCommand(@NonNull Object);
    method public void close();
    method public void close();
+180 −17
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.util.AndroidException;
import android.util.Log;
import android.util.Log;


import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParser;
@@ -68,35 +69,73 @@ import java.util.Set;
public final class ApplicationMediaCapabilities implements Parcelable {
public final class ApplicationMediaCapabilities implements Parcelable {
    private static final String TAG = "ApplicationMediaCapabilities";
    private static final String TAG = "ApplicationMediaCapabilities";


    /**
     * This exception is thrown when a given format is not specified in the media capabilities.
     */
    public static class FormatNotFoundException extends AndroidException {
        public FormatNotFoundException(@NonNull String format) {
            super(format);
        }
    }

    /** List of supported video codec mime types. */
    /** List of supported video codec mime types. */
    // TODO: init it with avc and mpeg4 as application is assuming to support them.
    // TODO: init it with avc and mpeg4 as application is assuming to support them.
    private Set<String> mSupportedVideoMimeTypes = new HashSet<>();
    private Set<String> mSupportedVideoMimeTypes = new HashSet<>();


    /** List of unsupported video codec mime types. */
    private Set<String> mUnsupportedVideoMimeTypes = new HashSet<>();

    /** List of supported hdr types. */
    /** List of supported hdr types. */
    private Set<String> mSupportedHdrTypes = new HashSet<>();
    private Set<String> mSupportedHdrTypes = new HashSet<>();


    /** List of unsupported hdr types. */
    private Set<String> mUnsupportedHdrTypes = new HashSet<>();

    private boolean mIsSlowMotionSupported = false;
    private boolean mIsSlowMotionSupported = false;


    private ApplicationMediaCapabilities(Builder b) {
    private ApplicationMediaCapabilities(Builder b) {
        mSupportedVideoMimeTypes.addAll(b.getSupportedVideoMimeTypes());
        mSupportedVideoMimeTypes.addAll(b.getSupportedVideoMimeTypes());
        mUnsupportedVideoMimeTypes.addAll(b.getUnsupportedVideoMimeTypes());
        mSupportedHdrTypes.addAll(b.getSupportedHdrTypes());
        mSupportedHdrTypes.addAll(b.getSupportedHdrTypes());
        mUnsupportedHdrTypes.addAll(b.getUnsupportedHdrTypes());
        mIsSlowMotionSupported = b.mIsSlowMotionSupported;
        mIsSlowMotionSupported = b.mIsSlowMotionSupported;
    }
    }


    /**
    /**
     * Query if an video codec is supported by the application.
     * Query if a video codec format is supported by the application.
     * @param videoMime The mime type of the video codec format. Must be the one used in
     * {@link MediaFormat#KEY_MIME}.
     * @return true if application supports the video codec format, false otherwise.
     * @throws FormatNotFoundException if the application did not specify the codec either in the
     * supported or unsupported formats.
     */
     */
    public boolean isVideoMimeTypeSupported(
    public boolean isVideoMimeTypeSupported(
            @NonNull String videoMime) {
            @NonNull String videoMime) throws FormatNotFoundException {
        return mSupportedVideoMimeTypes.contains(videoMime);
        if (mUnsupportedVideoMimeTypes.contains(videoMime)) {
            return false;
        } else if (mSupportedVideoMimeTypes.contains(videoMime)) {
            return true;
        } else {
            throw new FormatNotFoundException(videoMime);
        }
    }
    }


    /**
    /**
     * Query if a hdr type is supported by the application.
     * Query if a HDR type is supported by the application.
     * @param hdrType The type of the HDR format.
     * @return true if application supports the HDR format, false otherwise.
     * @throws FormatNotFoundException if the application did not specify the format either in the
     * supported or unsupported formats.
     */
     */
    public boolean isHdrTypeSupported(
    public boolean isHdrTypeSupported(
            @NonNull @MediaFeature.MediaHdrType String hdrType) {
            @NonNull @MediaFeature.MediaHdrType String hdrType) throws FormatNotFoundException {
        return mSupportedHdrTypes.contains(hdrType);
        if (mUnsupportedHdrTypes.contains(hdrType)) {
            return false;
        } else if (mSupportedHdrTypes.contains(hdrType)) {
            return true;
        } else {
            throw new FormatNotFoundException(hdrType);
        }
    }
    }


    @Override
    @Override
@@ -111,11 +150,21 @@ public final class ApplicationMediaCapabilities implements Parcelable {
        for (String cap : mSupportedVideoMimeTypes) {
        for (String cap : mSupportedVideoMimeTypes) {
            dest.writeString(cap);
            dest.writeString(cap);
        }
        }
        // Write out the unsupported video mime types.
        dest.writeInt(mUnsupportedVideoMimeTypes.size());
        for (String cap : mUnsupportedVideoMimeTypes) {
            dest.writeString(cap);
        }
        // Write out the supported hdr types.
        // Write out the supported hdr types.
        dest.writeInt(mSupportedHdrTypes.size());
        dest.writeInt(mSupportedHdrTypes.size());
        for (String cap : mSupportedHdrTypes) {
        for (String cap : mSupportedHdrTypes) {
            dest.writeString(cap);
            dest.writeString(cap);
        }
        }
        // Write out the unsupported hdr types.
        dest.writeInt(mUnsupportedHdrTypes.size());
        for (String cap : mUnsupportedHdrTypes) {
            dest.writeString(cap);
        }
        // Write out the supported slow motion.
        // Write out the supported slow motion.
        dest.writeBoolean(mIsSlowMotionSupported);
        dest.writeBoolean(mIsSlowMotionSupported);
    }
    }
@@ -124,7 +173,9 @@ public final class ApplicationMediaCapabilities implements Parcelable {
    public String toString() {
    public String toString() {
        String caps = new String(
        String caps = new String(
                "Supported Video MimeTypes: " + mSupportedVideoMimeTypes.toString());
                "Supported Video MimeTypes: " + mSupportedVideoMimeTypes.toString());
        caps += "Unsupported Video MimeTypes: " + mUnsupportedVideoMimeTypes.toString();
        caps += "Supported HDR types: " + mSupportedHdrTypes.toString();
        caps += "Supported HDR types: " + mSupportedHdrTypes.toString();
        caps += "Unsupported HDR types: " + mUnsupportedHdrTypes.toString();
        caps += "Supported slow motion: " + mIsSlowMotionSupported;
        caps += "Supported slow motion: " + mIsSlowMotionSupported;
        return caps;
        return caps;
    }
    }
@@ -159,9 +210,8 @@ public final class ApplicationMediaCapabilities implements Parcelable {
            };
            };


    /*
    /*
     * Returns a list that contains all the video codec mime types supported by the application.
     * Query the video codec mime types supported by the application.
     * The list will be empty if no codecs are supported by the application.
     * @return List of supported video codec mime types. The list will be empty if there are none.
     * @return List of supported video codec mime types.
     */
     */
    @NonNull
    @NonNull
    public List<String> getSupportedVideoMimeTypes() {
    public List<String> getSupportedVideoMimeTypes() {
@@ -169,15 +219,32 @@ public final class ApplicationMediaCapabilities implements Parcelable {
    }
    }


    /*
    /*
     * Returns a list that contains all hdr types supported by the application.
     * Query the video codec mime types that are not supported by the application.
     * The list will be empty if no hdr types are supported by the application.
     * @return List of unsupported video codec mime types. The list will be empty if there are none.
     * @return List of supported hdr types.
     */
    @NonNull
    public List<String> getUnsupportedVideoMimeTypes() {
        return new ArrayList<>(mSupportedVideoMimeTypes);
    }

    /*
     * Query all hdr types that are supported by the application.
     * @return List of supported hdr types. The list will be empty if there are none.
     */
     */
    @NonNull
    @NonNull
    public List<String> getSupportedHdrTypes() {
    public List<String> getSupportedHdrTypes() {
        return new ArrayList<>(mSupportedHdrTypes);
        return new ArrayList<>(mSupportedHdrTypes);
    }
    }


    /*
     * Query all hdr types that are not supported by the application.
     * @return List of unsupported hdr types. The list will be empty if there are none.
     */
    @NonNull
    public List<String> getUnsupportedHdrTypes()  {
        return new ArrayList<>(mUnsupportedHdrTypes);
    }

    /*
    /*
     * Whether handling of slow-motion video is supported
     * Whether handling of slow-motion video is supported
     */
     */
@@ -213,6 +280,12 @@ public final class ApplicationMediaCapabilities implements Parcelable {
        /** List of supported hdr types. */
        /** List of supported hdr types. */
        private Set<String> mSupportedHdrTypes = new HashSet<>();
        private Set<String> mSupportedHdrTypes = new HashSet<>();


        /** List of unsupported video codec mime types. */
        private Set<String> mUnsupportedVideoMimeTypes = new HashSet<>();

        /** List of unsupported hdr types. */
        private Set<String> mUnsupportedHdrTypes = new HashSet<>();

        private boolean mIsSlowMotionSupported = false;
        private boolean mIsSlowMotionSupported = false;


        /* Map to save the format read from the xml. */
        /* Map to save the format read from the xml. */
@@ -299,26 +372,50 @@ public final class ApplicationMediaCapabilities implements Parcelable {
                    case "HEVC":
                    case "HEVC":
                        if (isSupported) {
                        if (isSupported) {
                            mSupportedVideoMimeTypes.add(MediaFormat.MIMETYPE_VIDEO_HEVC);
                            mSupportedVideoMimeTypes.add(MediaFormat.MIMETYPE_VIDEO_HEVC);
                        } else {
                            mUnsupportedVideoMimeTypes.add(MediaFormat.MIMETYPE_VIDEO_HEVC);
                        }
                        break;
                    case "VP9":
                        if (isSupported) {
                            mSupportedVideoMimeTypes.add(MediaFormat.MIMETYPE_VIDEO_VP9);
                        } else {
                            mUnsupportedVideoMimeTypes.add(MediaFormat.MIMETYPE_VIDEO_VP9);
                        }
                        break;
                    case "AV1":
                        if (isSupported) {
                            mSupportedVideoMimeTypes.add(MediaFormat.MIMETYPE_VIDEO_AV1);
                        } else {
                            mUnsupportedVideoMimeTypes.add(MediaFormat.MIMETYPE_VIDEO_AV1);
                        }
                        }
                        break;
                        break;
                    case "HDR10":
                    case "HDR10":
                        if (isSupported) {
                        if (isSupported) {
                            mSupportedHdrTypes.add(MediaFeature.HdrType.HDR10);
                            mSupportedHdrTypes.add(MediaFeature.HdrType.HDR10);
                        } else {
                            mUnsupportedHdrTypes.add(MediaFeature.HdrType.HDR10);
                        }
                        }
                        break;
                        break;
                    case "HDR10Plus":
                    case "HDR10Plus":
                        if (isSupported) {
                        if (isSupported) {
                            mSupportedHdrTypes.add(MediaFeature.HdrType.HDR10_PLUS);
                            mSupportedHdrTypes.add(MediaFeature.HdrType.HDR10_PLUS);
                        } else {
                            mUnsupportedHdrTypes.add(MediaFeature.HdrType.HDR10_PLUS);
                        }
                        }
                        break;
                        break;
                    case "Dolby-Vision":
                    case "Dolby-Vision":
                        if (isSupported) {
                        if (isSupported) {
                            mSupportedHdrTypes.add(MediaFeature.HdrType.DOLBY_VISION);
                            mSupportedHdrTypes.add(MediaFeature.HdrType.DOLBY_VISION);
                        } else {
                            mUnsupportedHdrTypes.add(MediaFeature.HdrType.DOLBY_VISION);
                        }
                        }
                        break;
                        break;
                    case "HLG":
                    case "HLG":
                        if (isSupported) {
                        if (isSupported) {
                            mSupportedHdrTypes.add(MediaFeature.HdrType.HLG);
                            mSupportedHdrTypes.add(MediaFeature.HdrType.HLG);
                        } else {
                            mUnsupportedHdrTypes.add(MediaFeature.HdrType.HLG);
                        }
                        }
                        break;
                        break;
                    case "SlowMotion":
                    case "SlowMotion":
@@ -348,8 +445,11 @@ public final class ApplicationMediaCapabilities implements Parcelable {
        @NonNull
        @NonNull
        public ApplicationMediaCapabilities build() {
        public ApplicationMediaCapabilities build() {
            Log.d(TAG,
            Log.d(TAG,
                    "Building ApplicationMediaCapabilities with: " + mSupportedHdrTypes.toString()
                    "Building ApplicationMediaCapabilities with: (Supported HDR: "
                            + " " + mSupportedVideoMimeTypes.toString() + " "
                            + mSupportedHdrTypes.toString() + " Unsupported HDR: "
                            + mUnsupportedHdrTypes.toString() + ") (Supported Codec: "
                            + " " + mSupportedVideoMimeTypes.toString() + " Unsupported Codec:"
                            + mUnsupportedVideoMimeTypes.toString() + ") "
                            + mIsSlowMotionSupported);
                            + mIsSlowMotionSupported);


            // If hdr is supported, application must also support hevc.
            // If hdr is supported, application must also support hevc.
@@ -365,7 +465,6 @@ public final class ApplicationMediaCapabilities implements Parcelable {
         *
         *
         * @param codecMime Supported codec mime types. Must be one of the mime type defined
         * @param codecMime Supported codec mime types. Must be one of the mime type defined
         *                  in {@link MediaFormat}.
         *                  in {@link MediaFormat}.
         * @throws UnsupportedOperationException if the codec mime type is not supported.
         * @throws IllegalArgumentException if mime type is not valid.
         * @throws IllegalArgumentException if mime type is not valid.
         */
         */
        @NonNull
        @NonNull
@@ -379,16 +478,49 @@ public final class ApplicationMediaCapabilities implements Parcelable {
            return new ArrayList<>(mSupportedVideoMimeTypes);
            return new ArrayList<>(mSupportedVideoMimeTypes);
        }
        }


        private boolean isValidVideoCodecMimeType(@NonNull String codecMime) {
            if (!codecMime.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_HEVC)
                    && !codecMime.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_VP9)
                    && !codecMime.equalsIgnoreCase(MediaFormat.MIMETYPE_VIDEO_AV1)) {
                return false;
            }
            return true;
        }

        /**
         * Adds an unsupported video codec mime type.
         *
         * @param codecMime Unsupported codec mime type. Must be one of the mime type defined
         *                  in {@link MediaFormat}.
         * @throws IllegalArgumentException if mime type is not valid.
         */
        @NonNull
        public Builder addUnsupportedVideoMimeType(
                @NonNull String codecMime) {
            if (!isValidVideoCodecMimeType(codecMime)) {
                throw new IllegalArgumentException("Invalid codec mime type: " + codecMime);
            }
            mUnsupportedVideoMimeTypes.add(codecMime);
            return this;
        }

        private List<String> getUnsupportedVideoMimeTypes() {
            return new ArrayList<>(mUnsupportedVideoMimeTypes);
        }

        /**
        /**
         * Adds a supported hdr type.
         * Adds a supported hdr type.
         *
         *
         * @param hdrType Supported hdr types. Must be one of the String defined in
         * @param hdrType Supported hdr type. Must be one of the String defined in
         *                {@link MediaFeature.HdrType}.
         *                {@link MediaFeature.HdrType}.
         * @throws IllegalArgumentException if hdrType is not valid.
         * @throws IllegalArgumentException if hdrType is not valid.
         */
         */
        @NonNull
        @NonNull
        public Builder addSupportedHdrType(
        public Builder addSupportedHdrType(
                @NonNull @MediaFeature.MediaHdrType String hdrType) {
                @NonNull @MediaFeature.MediaHdrType String hdrType) {
            if (!isValidVideoCodecHdrType(hdrType)) {
                throw new IllegalArgumentException("Invalid hdr type: " + hdrType);
            }
            mSupportedHdrTypes.add(hdrType);
            mSupportedHdrTypes.add(hdrType);
            return this;
            return this;
        }
        }
@@ -397,6 +529,37 @@ public final class ApplicationMediaCapabilities implements Parcelable {
            return new ArrayList<>(mSupportedHdrTypes);
            return new ArrayList<>(mSupportedHdrTypes);
        }
        }


        private boolean isValidVideoCodecHdrType(@NonNull String hdrType) {
            if (!hdrType.equals(MediaFeature.HdrType.DOLBY_VISION)
                    && !hdrType.equals(MediaFeature.HdrType.HDR10)
                    && !hdrType.equals(MediaFeature.HdrType.HDR10_PLUS)
                    && !hdrType.equals(MediaFeature.HdrType.HLG)) {
                return false;
            }
            return true;
        }

        /**
         * Adds an unsupported hdr type.
         *
         * @param hdrType Unsupported hdr type. Must be one of the String defined in
         *                {@link MediaFeature.HdrType}.
         * @throws IllegalArgumentException if hdrType is not valid.
         */
        @NonNull
        public Builder addUnsupportedHdrType(
                @NonNull @MediaFeature.MediaHdrType String hdrType) {
            if (!isValidVideoCodecHdrType(hdrType)) {
                throw new IllegalArgumentException("Invalid hdr type: " + hdrType);
            }
            mUnsupportedHdrTypes.add(hdrType);
            return this;
        }

        private List<String> getUnsupportedHdrTypes() {
            return new ArrayList<>(mUnsupportedHdrTypes);
        }

        /**
        /**
         * Sets whether slow-motion video is supported.
         * Sets whether slow-motion video is supported.
         * If an application indicates support for slow-motion, it is application's responsibility
         * If an application indicates support for slow-motion, it is application's responsibility
+9 −2
Original line number Original line Diff line number Diff line
@@ -980,8 +980,15 @@ public final class MediaTranscodeManager {
                    throw new UnsupportedOperationException(
                    throw new UnsupportedOperationException(
                            "Source video format hint must be set!");
                            "Source video format hint must be set!");
                }
                }
                boolean supportHevc = mClientCaps.isVideoMimeTypeSupported(

                boolean supportHevc = false;
                try {
                    supportHevc = mClientCaps.isVideoMimeTypeSupported(
                            MediaFormat.MIMETYPE_VIDEO_HEVC);
                            MediaFormat.MIMETYPE_VIDEO_HEVC);
                } catch (ApplicationMediaCapabilities.FormatNotFoundException ex) {
                    // Set to false if application did not specify.
                    supportHevc = false;
                }
                if (!supportHevc && MediaFormat.MIMETYPE_VIDEO_HEVC.equals(
                if (!supportHevc && MediaFormat.MIMETYPE_VIDEO_HEVC.equals(
                        mSrcVideoFormatHint.getString(MediaFormat.KEY_MIME))) {
                        mSrcVideoFormatHint.getString(MediaFormat.KEY_MIME))) {
                    return true;
                    return true;