Merge "MediaDataSource: address API council comments" into mnc-dev
This commit is contained in:
@@ -15673,9 +15673,10 @@ package android.media {
|
|||||||
ctor public MediaCryptoException(java.lang.String);
|
ctor public MediaCryptoException(java.lang.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract interface MediaDataSource implements java.io.Closeable {
|
public abstract class MediaDataSource implements java.io.Closeable {
|
||||||
method public abstract long getSize();
|
ctor public MediaDataSource();
|
||||||
method public abstract int readAt(long, byte[], int);
|
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 {
|
public class MediaDescription implements android.os.Parcelable {
|
||||||
|
|||||||
@@ -16910,9 +16910,10 @@ package android.media {
|
|||||||
ctor public MediaCryptoException(java.lang.String);
|
ctor public MediaCryptoException(java.lang.String);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract interface MediaDataSource implements java.io.Closeable {
|
public abstract class MediaDataSource implements java.io.Closeable {
|
||||||
method public abstract long getSize();
|
ctor public MediaDataSource();
|
||||||
method public abstract int readAt(long, byte[], int);
|
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 {
|
public class MediaDescription implements android.os.Parcelable {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package android.media;
|
package android.media;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For supplying media data to the framework. Implement this if your app has
|
* 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
|
* 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>
|
* 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.
|
* Called to request data from the given position.
|
||||||
*
|
*
|
||||||
* Implementations should should write up to {@code size} bytes into
|
* Implementations should should write up to {@code size} bytes into
|
||||||
* {@code buffer}, and return the number of bytes written.
|
* {@code buffer}, and return the number of bytes written.
|
||||||
*
|
*
|
||||||
* Return {@code 0} to indicate that {@code position} is at, or beyond, the
|
* Return {@code 0} if size is zero (thus no bytes are read).
|
||||||
* end of the source.
|
|
||||||
*
|
*
|
||||||
* Return {@code -1} to indicate that a fatal error occurred. The failed
|
* Return {@code -1} to indicate that end of stream is reached.
|
||||||
* 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 position the position in the data source to read from.
|
* @param position the position in the data source to read from.
|
||||||
* @param buffer the buffer to read the data into.
|
* @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.
|
* @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.
|
* @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.
|
* 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.
|
* @return the size of data source in bytes, or -1 if the size is unknown.
|
||||||
*/
|
*/
|
||||||
public long getSize();
|
public abstract long getSize() throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ JMediaDataSource::JMediaDataSource(JNIEnv* env, jobject source)
|
|||||||
ScopedLocalRef<jclass> mediaDataSourceClass(env, env->GetObjectClass(mMediaDataSourceObj));
|
ScopedLocalRef<jclass> mediaDataSourceClass(env, env->GetObjectClass(mMediaDataSourceObj));
|
||||||
CHECK(mediaDataSourceClass.get() != NULL);
|
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);
|
CHECK(mReadMethod != NULL);
|
||||||
mGetSizeMethod = env->GetMethodID(mediaDataSourceClass.get(), "getSize", "()J");
|
mGetSizeMethod = env->GetMethodID(mediaDataSourceClass.get(), "getSize", "()J");
|
||||||
CHECK(mGetSizeMethod != NULL);
|
CHECK(mGetSizeMethod != NULL);
|
||||||
@@ -80,7 +80,7 @@ ssize_t JMediaDataSource::readAt(off64_t offset, size_t size) {
|
|||||||
|
|
||||||
JNIEnv* env = AndroidRuntime::getJNIEnv();
|
JNIEnv* env = AndroidRuntime::getJNIEnv();
|
||||||
jint numread = env->CallIntMethod(mMediaDataSourceObj, mReadMethod,
|
jint numread = env->CallIntMethod(mMediaDataSourceObj, mReadMethod,
|
||||||
(jlong)offset, mByteArrayObj, (jint)size);
|
(jlong)offset, mByteArrayObj, (jint)0, (jint)size);
|
||||||
if (env->ExceptionCheck()) {
|
if (env->ExceptionCheck()) {
|
||||||
ALOGW("An exception occurred in readAt()");
|
ALOGW("An exception occurred in readAt()");
|
||||||
LOGW_EX(env);
|
LOGW_EX(env);
|
||||||
@@ -89,9 +89,14 @@ ssize_t JMediaDataSource::readAt(off64_t offset, size_t size) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (numread < 0) {
|
if (numread < 0) {
|
||||||
ALOGW("An error occurred in readAt()");
|
if (numread != -1) {
|
||||||
mJavaObjStatus = UNKNOWN_ERROR;
|
ALOGW("An error occurred in readAt()");
|
||||||
return -1;
|
mJavaObjStatus = UNKNOWN_ERROR;
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
// numread == -1 indicates EOF
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((size_t)numread > size) {
|
if ((size_t)numread > size) {
|
||||||
ALOGE("readAt read too many bytes.");
|
ALOGE("readAt read too many bytes.");
|
||||||
|
|||||||
@@ -715,6 +715,11 @@ static void android_media_MediaExtractor_setDataSourceCallback(
|
|||||||
status_t err = extractor->setDataSource(bridge);
|
status_t err = extractor->setDataSource(bridge);
|
||||||
|
|
||||||
if (err != OK) {
|
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(
|
jniThrowException(
|
||||||
env,
|
env,
|
||||||
"java/io/IOException",
|
"java/io/IOException",
|
||||||
|
|||||||
Reference in New Issue
Block a user