Merge "Frameworks/base: Fix old code in MediaPlayer"

This commit is contained in:
Andreas Gampe
2016-04-16 00:40:00 +00:00
committed by Gerrit Code Review

View File

@@ -2446,9 +2446,9 @@ public class MediaPlayer implements SubtitleController.Listener
throw new IllegalArgumentException("Illegal mimeType for timed text source: " + mime);
}
FileDescriptor fd2;
final FileDescriptor dupedFd;
try {
fd2 = Libcore.os.dup(fd);
dupedFd = Libcore.os.dup(fd);
} catch (ErrnoException ex) {
Log.e(TAG, ex.getMessage(), ex);
throw new RuntimeException(ex);
@@ -2473,7 +2473,6 @@ public class MediaPlayer implements SubtitleController.Listener
mIndexTrackPairs.add(Pair.<Integer, SubtitleTrack>create(null, track));
}
final FileDescriptor fd3 = fd2;
final long offset2 = offset;
final long length2 = length;
final HandlerThread thread = new HandlerThread(
@@ -2483,14 +2482,13 @@ public class MediaPlayer implements SubtitleController.Listener
Handler handler = new Handler(thread.getLooper());
handler.post(new Runnable() {
private int addTrack() {
InputStream is = null;
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
Libcore.os.lseek(fd3, offset2, OsConstants.SEEK_SET);
Libcore.os.lseek(dupedFd, offset2, OsConstants.SEEK_SET);
byte[] buffer = new byte[4096];
for (long total = 0; total < length2;) {
int bytesToRead = (int) Math.min(buffer.length, length2 - total);
int bytes = IoBridge.read(fd3, buffer, 0, bytesToRead);
int bytes = IoBridge.read(dupedFd, buffer, 0, bytesToRead);
if (bytes < 0) {
break;
} else {
@@ -2504,12 +2502,10 @@ public class MediaPlayer implements SubtitleController.Listener
Log.e(TAG, e.getMessage(), e);
return MEDIA_INFO_TIMED_TEXT_ERROR;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
}
try {
Libcore.os.close(dupedFd);
} catch (ErrnoException e) {
Log.e(TAG, e.getMessage(), e);
}
}
}