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

Commit e4f1cb24 authored by Dongwon Kang's avatar Dongwon Kang Committed by Android (Google) Code Review
Browse files

Merge "Use ProxyFileDescriptorCallback instead of DataSourceCallback"

parents 9050dc68 77ab9864
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -23760,12 +23760,6 @@ package android.media {
    field public static final int QUALITY_MEDIUM = 1; // 0x1
  }
  public abstract class DataSourceCallback implements java.io.Closeable {
    ctor public DataSourceCallback();
    method public abstract long getSize() throws java.io.IOException;
    method public abstract int readAt(long, @NonNull byte[], int, int) throws java.io.IOException;
  }
  public class DataSourceDesc {
    method public long getEndPosition();
    method @Nullable public String getMediaId();
@@ -23782,7 +23776,6 @@ package android.media {
    method @NonNull public android.media.DataSourceDesc.Builder setDataSource(@NonNull android.net.Uri, @Nullable java.util.Map<java.lang.String,java.lang.String>, @Nullable java.util.List<java.net.HttpCookie>);
    method @NonNull public android.media.DataSourceDesc.Builder setDataSource(@NonNull android.os.ParcelFileDescriptor);
    method @NonNull public android.media.DataSourceDesc.Builder setDataSource(@NonNull android.os.ParcelFileDescriptor, long, long);
    method @NonNull public android.media.DataSourceDesc.Builder setDataSource(@NonNull android.media.DataSourceCallback);
    method @NonNull public android.media.DataSourceDesc.Builder setEndPosition(long);
    method @NonNull public android.media.DataSourceDesc.Builder setMediaId(@Nullable String);
    method @NonNull public android.media.DataSourceDesc.Builder setStartPosition(long);
+0 −4
Original line number Diff line number Diff line
@@ -1078,10 +1078,6 @@ package android.media {
    method public android.media.BufferingParams.Builder setResumePlaybackMarkMs(int);
  }

  public class CallbackDataSourceDesc extends android.media.DataSourceDesc {
    method @NonNull public android.media.DataSourceCallback getDataSourceCallback();
  }

  public class FileDataSourceDesc extends android.media.DataSourceDesc {
    method public long getLength();
    method public long getOffset();
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,6 @@ filegroup {
        "apex/java/android/media/DataSourceDesc.java",
        "apex/java/android/media/UriDataSourceDesc.java",
        "apex/java/android/media/FileDataSourceDesc.java",
        "apex/java/android/media/CallbackDataSourceDesc.java",
        "apex/java/android/media/Media2Utils.java",
        "apex/java/android/media/MediaPlayer2Utils.java",
        "apex/java/android/media/MediaPlayer2.java",
@@ -98,6 +97,7 @@ filegroup {
        "apex/java/android/media/Media2HTTPConnection.java",
        "apex/java/android/media/RoutingDelegate.java",
        "apex/java/android/media/BufferingParams.java",
        "apex/java/android/media/ProxyDataSourceCallback.java",
    ],
}

+5 −1
Original line number Diff line number Diff line
@@ -32,8 +32,12 @@ import java.io.IOException;
 * you don't need to do your own synchronization unless you're modifying the
 * DataSourceCallback from another thread while it's being used by the framework.</p>
 *
 * @hide
 */
public abstract class DataSourceCallback implements Closeable {

    public static final int END_OF_STREAM = -1;

    /**
     * Called to request data from the given position.
     *
@@ -49,7 +53,7 @@ public abstract class DataSourceCallback implements Closeable {
     * @param offset the offset within buffer to read the data into.
     * @param size the number of bytes to read.
     * @throws IOException on fatal errors.
     * @return the number of bytes read, or -1 if end of stream is reached.
     * @return the number of bytes read, or {@link #END_OF_STREAM} if end of stream is reached.
     */
    public abstract int readAt(long position, @NonNull byte[] buffer, int offset, int size)
            throws IOException;
+5 −27
Original line number Diff line number Diff line
@@ -125,7 +125,6 @@ public class DataSourceDesc {
        private static final int SOURCE_TYPE_UNKNOWN = 0;
        private static final int SOURCE_TYPE_URI = 1;
        private static final int SOURCE_TYPE_FILE = 2;
        private static final int SOURCE_TYPE_CALLBACK = 3;

        private int mSourceType = SOURCE_TYPE_UNKNOWN;
        private String mMediaId;
@@ -142,9 +141,6 @@ public class DataSourceDesc {
        private long mOffset = 0;
        private long mLength = FileDataSourceDesc.FD_LENGTH_UNKNOWN;

        // For CallbackDataSourceDesc
        private DataSourceCallback mDataSourceCallback;

        /**
         * Constructs a new BuilderBase with the defaults.
         */
@@ -173,9 +169,6 @@ public class DataSourceDesc {
                mUri = ((UriDataSourceDesc) dsd).getUri();
                mHeader = ((UriDataSourceDesc) dsd).getHeaders();
                mCookies = ((UriDataSourceDesc) dsd).getCookies();
            } else if (dsd instanceof CallbackDataSourceDesc) {
                mSourceType = SOURCE_TYPE_CALLBACK;
                mDataSourceCallback = ((CallbackDataSourceDesc) dsd).getDataSourceCallback();
            } else {
                throw new IllegalStateException("Unknown source type:" + mSourceType);
            }
@@ -204,9 +197,6 @@ public class DataSourceDesc {
            } else if (mSourceType == SOURCE_TYPE_URI) {
                desc = new UriDataSourceDesc(
                        mMediaId, mStartPositionMs, mEndPositionMs, mUri, mHeader, mCookies);
            } else if (mSourceType == SOURCE_TYPE_CALLBACK) {
                desc = new CallbackDataSourceDesc(
                        mMediaId, mStartPositionMs, mEndPositionMs, mDataSourceCallback);
            } else {
                throw new IllegalStateException("Unknown source type:" + mSourceType);
            }
@@ -326,7 +316,7 @@ public class DataSourceDesc {

        /**
         * Sets the data source (ParcelFileDescriptor) to use. The ParcelFileDescriptor must be
         * seekable (N.B. a LocalSocket is not seekable). When the {@link FileDataSourceDesc}
         * seekable (N.B. a LocalSocket is not seekable). When the {@link DataSourceDesc}
         * created by this builder is passed to {@link MediaPlayer2} via
         * {@link MediaPlayer2#setDataSource},
         * {@link MediaPlayer2#setNextDataSource} or
@@ -347,7 +337,7 @@ public class DataSourceDesc {

        /**
         * Sets the data source (ParcelFileDescriptor) to use. The ParcelFileDescriptor must be
         * seekable (N.B. a LocalSocket is not seekable). When the {@link FileDataSourceDesc}
         * seekable (N.B. a LocalSocket is not seekable). When the {@link DataSourceDesc}
         * created by this builder is passed to {@link MediaPlayer2} via
         * {@link MediaPlayer2#setDataSource},
         * {@link MediaPlayer2#setNextDataSource} or
@@ -367,7 +357,9 @@ public class DataSourceDesc {
        public Builder setDataSource(
                @NonNull ParcelFileDescriptor pfd, long offset, long length) {
            setSourceType(SOURCE_TYPE_FILE);
            Media2Utils.checkArgument(pfd != null, "pfd cannot be null.");
            if (pfd == null) {
                throw new NullPointerException("pfd cannot be null.");
            }
            if (offset < 0) {
                offset = 0;
            }
@@ -380,20 +372,6 @@ public class DataSourceDesc {
            return this;
        }

        /**
         * Sets the data source (DataSourceCallback) to use.
         *
         * @param dscb the DataSourceCallback for the media to play
         * @return the same Builder instance.
         * @throws NullPointerException if dscb is null.
         */
        public @NonNull Builder setDataSource(@NonNull DataSourceCallback dscb) {
            setSourceType(SOURCE_TYPE_CALLBACK);
            Media2Utils.checkArgument(dscb != null, "data source cannot be null.");
            mDataSourceCallback = dscb;
            return this;
        }

        private void setSourceType(int type) {
            if (mSourceType != SOURCE_TYPE_UNKNOWN) {
                throw new IllegalStateException("Source is already set. type=" + mSourceType);
Loading