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

Commit b27d3858 authored by Chong Zhang's avatar Chong Zhang Committed by Android Git Automerger
Browse files

am 7fc802bb: Merge "MediaDataSource: address API council comments" into mnc-dev

* commit '7fc802bb':
  MediaDataSource: address API council comments
parents 6500bbd4 7fc802bb
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -15673,9 +15673,10 @@ 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 abstract class MediaDataSource implements java.io.Closeable {
    ctor public MediaDataSource();
    method public abstract long getSize() throws java.io.IOException;
    method public abstract int readAt(long, byte[], int, int) throws java.io.IOException;
  }
  public class MediaDescription implements android.os.Parcelable {
+4 −3
Original line number Diff line number Diff line
@@ -16910,9 +16910,10 @@ 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 abstract class MediaDataSource implements java.io.Closeable {
    ctor public MediaDataSource();
    method public abstract long getSize() throws java.io.IOException;
    method public abstract int readAt(long, byte[], int, int) throws java.io.IOException;
  }
  public class MediaDescription implements android.os.Parcelable {
+10 −11
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
package android.media;

import java.io.Closeable;
import java.io.IOException;

/**
 * For supplying media data to the framework. Implement this if your app has
@@ -29,34 +30,32 @@ import java.io.Closeable;
 * 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 MediaDataSource extends Closeable {
public abstract class MediaDataSource implements Closeable {
    /**
     * 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 0} if size is zero (thus no bytes are read).
     *
     * 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}.
     * Return {@code -1} to indicate that end of stream is reached.
     *
     * @param position the position in the data source to read from.
     * @param buffer the buffer to read the data into.
     * @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 there was an error.
     */
    public int readAt(long position, byte[] buffer, int size);
    public abstract int readAt(long position, byte[] buffer, int offset, int size)
            throws IOException;

    /**
     * Called to get the size of the data source.
     *
     * @throws IOException on fatal errors
     * @return the size of data source in bytes, or -1 if the size is unknown.
     */
    public long getSize();
    public abstract long getSize() throws IOException;
}
+10 −5
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ JMediaDataSource::JMediaDataSource(JNIEnv* env, jobject source)
    ScopedLocalRef<jclass> mediaDataSourceClass(env, env->GetObjectClass(mMediaDataSourceObj));
    CHECK(mediaDataSourceClass.get() != NULL);

    mReadMethod = env->GetMethodID(mediaDataSourceClass.get(), "readAt", "(J[BI)I");
    mReadMethod = env->GetMethodID(mediaDataSourceClass.get(), "readAt", "(J[BII)I");
    CHECK(mReadMethod != NULL);
    mGetSizeMethod = env->GetMethodID(mediaDataSourceClass.get(), "getSize", "()J");
    CHECK(mGetSizeMethod != NULL);
@@ -80,7 +80,7 @@ ssize_t JMediaDataSource::readAt(off64_t offset, size_t size) {

    JNIEnv* env = AndroidRuntime::getJNIEnv();
    jint numread = env->CallIntMethod(mMediaDataSourceObj, mReadMethod,
                                      (jlong)offset, mByteArrayObj, (jint)size);
            (jlong)offset, mByteArrayObj, (jint)0, (jint)size);
    if (env->ExceptionCheck()) {
        ALOGW("An exception occurred in readAt()");
        LOGW_EX(env);
@@ -89,9 +89,14 @@ ssize_t JMediaDataSource::readAt(off64_t offset, size_t size) {
        return -1;
    }
    if (numread < 0) {
        if (numread != -1) {
            ALOGW("An error occurred in readAt()");
            mJavaObjStatus = UNKNOWN_ERROR;
            return -1;
        } else {
            // numread == -1 indicates EOF
            return 0;
        }
    }
    if ((size_t)numread > size) {
        ALOGE("readAt read too many bytes.");
+5 −0
Original line number Diff line number Diff line
@@ -715,6 +715,11 @@ static void android_media_MediaExtractor_setDataSourceCallback(
    status_t err = extractor->setDataSource(bridge);

    if (err != OK) {
        // Clear bridge so that JMediaDataSource::close() is called _before_
        // we throw the IOException.
        // Otherwise close() gets called when we go out of scope, it calls
        // Java with a pending exception and crashes the process.
        bridge.clear();
        jniThrowException(
                env,
                "java/io/IOException",