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

Commit 4eaa2938 authored by Chris Watkins's avatar Chris Watkins
Browse files

Unhide the android.media.[Media]DataSource interface.

This allows apps to implement MediaDataSource, which is modeled on
stagefright's DataSource, to supply media data to the framework. This
was already implemented for MediaExtractor, but it was renamed from
DataSource.

MediaExtractor, MediaPlayer and MediaMetadataRetriever each have a new
overload: #setDataSource(android.media.MediaDataSource)

Only NuPlayer supports this new data source.

The change introduces:
 * IDataSource:        The binder interface for DataSource.
 * JMediaDataSource:   The native counterpart to the java interface. It
                       implements IDataSource.
 * CallbackDataSource: A stagefright DataSource that wraps an IDataSource.

Change-Id: I6d9c1167b4a7384c469b1e928f31791a7ebed716
parent ca25b876
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -15444,6 +15444,11 @@ package android.media {
    ctor public MediaCryptoException(java.lang.String);
  }
  public abstract interface MediaDataSource implements java.io.Closeable {
    method public abstract long getSize();
    method public abstract int readAt(long, byte[], int);
  }
  public class MediaDescription implements android.os.Parcelable {
    method public int describeContents();
    method public java.lang.CharSequence getDescription();
@@ -15579,6 +15584,7 @@ package android.media {
    method public final void release();
    method public void seekTo(long, int);
    method public void selectTrack(int);
    method public final void setDataSource(android.media.MediaDataSource) throws java.io.IOException, java.lang.IllegalArgumentException;
    method public final void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>) throws java.io.IOException;
    method public final void setDataSource(java.lang.String, java.util.Map<java.lang.String, java.lang.String>) throws java.io.IOException;
    method public final void setDataSource(java.lang.String) throws java.io.IOException;
@@ -15758,6 +15764,7 @@ package android.media {
    method public void setDataSource(java.io.FileDescriptor, long, long) throws java.lang.IllegalArgumentException;
    method public void setDataSource(java.io.FileDescriptor) throws java.lang.IllegalArgumentException;
    method public void setDataSource(android.content.Context, android.net.Uri) throws java.lang.IllegalArgumentException, java.lang.SecurityException;
    method public void setDataSource(android.media.MediaDataSource) throws java.lang.IllegalArgumentException;
    field public static final int METADATA_KEY_ALBUM = 1; // 0x1
    field public static final int METADATA_KEY_ALBUMARTIST = 13; // 0xd
    field public static final int METADATA_KEY_ARTIST = 2; // 0x2
@@ -15842,6 +15849,7 @@ package android.media {
    method public void setDataSource(java.lang.String) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(java.io.FileDescriptor) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
    method public void setDataSource(java.io.FileDescriptor, long, long) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
    method public void setDataSource(android.media.MediaDataSource) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException;
    method public void setDisplay(android.view.SurfaceHolder);
    method public void setLooping(boolean);
    method public void setNextMediaPlayer(android.media.MediaPlayer);
+8 −0
Original line number Diff line number Diff line
@@ -16656,6 +16656,11 @@ package android.media {
    ctor public MediaCryptoException(java.lang.String);
  }
  public abstract interface MediaDataSource implements java.io.Closeable {
    method public abstract long getSize();
    method public abstract int readAt(long, byte[], int);
  }
  public class MediaDescription implements android.os.Parcelable {
    method public int describeContents();
    method public java.lang.CharSequence getDescription();
@@ -16792,6 +16797,7 @@ package android.media {
    method public final void release();
    method public void seekTo(long, int);
    method public void selectTrack(int);
    method public final void setDataSource(android.media.MediaDataSource) throws java.io.IOException, java.lang.IllegalArgumentException;
    method public final void setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>) throws java.io.IOException;
    method public final void setDataSource(java.lang.String, java.util.Map<java.lang.String, java.lang.String>) throws java.io.IOException;
    method public final void setDataSource(java.lang.String) throws java.io.IOException;
@@ -16971,6 +16977,7 @@ package android.media {
    method public void setDataSource(java.io.FileDescriptor, long, long) throws java.lang.IllegalArgumentException;
    method public void setDataSource(java.io.FileDescriptor) throws java.lang.IllegalArgumentException;
    method public void setDataSource(android.content.Context, android.net.Uri) throws java.lang.IllegalArgumentException, java.lang.SecurityException;
    method public void setDataSource(android.media.MediaDataSource) throws java.lang.IllegalArgumentException;
    field public static final int METADATA_KEY_ALBUM = 1; // 0x1
    field public static final int METADATA_KEY_ALBUMARTIST = 13; // 0xd
    field public static final int METADATA_KEY_ARTIST = 2; // 0x2
@@ -17055,6 +17062,7 @@ package android.media {
    method public void setDataSource(java.lang.String) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException, java.lang.SecurityException;
    method public void setDataSource(java.io.FileDescriptor) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
    method public void setDataSource(java.io.FileDescriptor, long, long) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.IllegalStateException;
    method public void setDataSource(android.media.MediaDataSource) throws java.lang.IllegalArgumentException, java.lang.IllegalStateException;
    method public void setDisplay(android.view.SurfaceHolder);
    method public void setLooping(boolean);
    method public void setNextMediaPlayer(android.media.MediaPlayer);
+62 −0
Original line number Diff line number Diff line
@@ -20,24 +20,43 @@ package android.media;
import java.io.Closeable;

/**
 * An abstraction for a media data source, e.g. a file or an http stream
 * {@hide}
 * For supplying media data to the framework. Implement this if your app has
 * special requirements for the way media data is obtained.
 *
 * <p class="note">Methods of this interface may be called on multiple different
 * threads. There will be a thread synchronization point between each call to ensure that
 * modifications to the state of your MediaDataSource are visible to future calls. This means
 * you don't need to do your own synchronization unless you're modifying the
 * MediaDataSource from another thread while it's being used by the framework.</p>
 */
public interface DataSource extends Closeable {
public interface MediaDataSource extends Closeable {
    /**
     * Reads data from the data source at the requested position
     * Called to request data from the given position.
     *
     * Implementations should should write up to {@code size} bytes into
     * {@code buffer}, and return the number of bytes written.
     *
     * Return {@code 0} to indicate that {@code position} is at, or beyond, the
     * end of the source.
     *
     * Return {@code -1} to indicate that a fatal error occurred. The failed
     * read will not be retried, so transient errors should be handled
     * internally.
     *
     * Throwing an exception from this method will have the same effect as
     * returning {@code -1}.
     *
     * @param offset where in the source to read
     * @param buffer the buffer to read the data into
     * @param size how many bytes to read
     * @return the number of bytes read, or -1 if there was an error
     * @param position the position in the data source to read from.
     * @param buffer the buffer to read the data into.
     * @param size the number of bytes to read.
     * @return the number of bytes read, or -1 if there was an error.
     */
    public int readAt(long offset, byte[] buffer, int size);
    public int readAt(long position, byte[] buffer, int size);

    /**
     * Gets the size of the data source.
     * Called to get the size of the data source.
     *
     * @return size of data source, or -1 if the length is unknown
     * @return the size of data source in bytes, or -1 if the size is unknown.
     */
    public long getSize();
}
+4 −3
Original line number Diff line number Diff line
@@ -66,10 +66,11 @@ final public class MediaExtractor {
    }

    /**
     * Sets the DataSource object to be used as the data source for this extractor
     * {@hide}
     * Sets the data source (MediaDataSource) to use.
     *
     * @param dataSource the MediaDataSource for the media you want to extract from
     */
    public native final void setDataSource(DataSource source) throws IOException;
    public native final void setDataSource(MediaDataSource dataSource) throws IllegalArgumentException, IOException;

    /**
     * Sets the data source as a content Uri.
+14 −1
Original line number Diff line number Diff line
@@ -202,6 +202,19 @@ public class MediaMetadataRetriever
        setDataSource(uri.toString());
    }

    /**
     * Sets the data source (MediaDataSource) to use.
     *
     * @param dataSource the MediaDataSource for the media you want to play
     */
    public void setDataSource(MediaDataSource dataSource)
            throws IllegalArgumentException {
        _setDataSource(dataSource);
    }

    private native void _setDataSource(MediaDataSource dataSource)
          throws IllegalArgumentException;

    /**
     * Call this method after setDataSource(). This method retrieves the
     * meta data value associated with the keyCode.
Loading