From a085d2f29b24f3d6ae85fcd10d654c723eac32af Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Fri, 10 Apr 2015 23:00:23 +0100 Subject: [PATCH] Add END_OF_INPUT constant + start using it. --- .../src/main/java/com/google/android/exoplayer/C.java | 11 ++++++++--- .../google/android/exoplayer/upstream/DataSource.java | 3 ++- .../exoplayer/upstream/DefaultHttpDataSource.java | 7 ++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/C.java b/library/src/main/java/com/google/android/exoplayer/C.java index 8ff7888ad0..0c43fd50d0 100644 --- a/library/src/main/java/com/google/android/exoplayer/C.java +++ b/library/src/main/java/com/google/android/exoplayer/C.java @@ -43,6 +43,12 @@ public final class C { */ public static final String UTF8_NAME = "UTF-8"; + /** + * @see MediaCodec#CRYPTO_MODE_AES_CTR + */ + @SuppressWarnings("InlinedApi") + public static final int CRYPTO_MODE_AES_CTR = MediaCodec.CRYPTO_MODE_AES_CTR; + /** * @see MediaExtractor#SAMPLE_FLAG_SYNC */ @@ -61,10 +67,9 @@ public final class C { public static final int SAMPLE_FLAG_DECODE_ONLY = 0x8000000; /** - * @see MediaCodec#CRYPTO_MODE_AES_CTR + * A return value for methods where the end of an input was encountered. */ - @SuppressWarnings("InlinedApi") - public static final int CRYPTO_MODE_AES_CTR = MediaCodec.CRYPTO_MODE_AES_CTR; + public static final int RESULT_END_OF_INPUT = -1; private C() {} diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/DataSource.java b/library/src/main/java/com/google/android/exoplayer/upstream/DataSource.java index 21f3488f7f..3d711708ee 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/DataSource.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/DataSource.java @@ -63,7 +63,8 @@ public interface DataSource { * @param buffer The buffer into which the read data should be stored. * @param offset The start offset into {@code buffer} at which data should be written. * @param readLength The maximum number of bytes to read. - * @return The number of bytes read, or -1 if the end of the opened range is reached. + * @return The number of bytes read, or {@link C#RESULT_END_OF_INPUT} if the end of the opened + * range is reached. * @throws IOException If an error occurs reading from the source. */ public int read(byte[] buffer, int offset, int readLength) throws IOException; diff --git a/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java b/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java index 49a00fa400..d809b28110 100644 --- a/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java +++ b/library/src/main/java/com/google/android/exoplayer/upstream/DefaultHttpDataSource.java @@ -401,7 +401,8 @@ public class DefaultHttpDataSource implements HttpDataSource { * @param buffer The buffer into which the read data should be stored. * @param offset The start offset into {@code buffer} at which data should be written. * @param readLength The maximum number of bytes to read. - * @return The number of bytes read, or -1 if the end of the opened range is reached. + * @return The number of bytes read, or {@link C#RESULT_END_OF_INPUT} if the end of the opened + * range is reached. * @throws IOException If an error occurs reading from the source. */ private int readInternal(byte[] buffer, int offset, int readLength) throws IOException { @@ -409,7 +410,7 @@ public class DefaultHttpDataSource implements HttpDataSource { : (int) Math.min(readLength, bytesToRead - bytesRead); if (readLength == 0) { // We've read all of the requested data. - return -1; + return C.RESULT_END_OF_INPUT; } int read = inputStream.read(buffer, offset, readLength); @@ -418,7 +419,7 @@ public class DefaultHttpDataSource implements HttpDataSource { // The server closed the connection having not sent sufficient data. throw new EOFException(); } - return -1; + return C.RESULT_END_OF_INPUT; } bytesRead += read;