Skip to content

Commit

Permalink
Move to first offset after prepare
Browse files Browse the repository at this point in the history
If a file contained meta data at the end, the datasource
would reach end of file during prepare phase. When the playback
was started the datasource needed to be reconnected at the
first sample offset, meaning that no data had been buffered between
prepare() and start().
  • Loading branch information
Oscar Rydhé authored and Jimmy Dahlqvist committed Apr 1, 2015
1 parent a967ac4 commit 43e0fa5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ protected void doCloseSilently(Closeable c) {
@Override
public abstract int readAt(long offset, byte[] buffer, int size) throws IOException;

@Override
public void requestReadPosition(long offset) throws IOException {
// Empty implementation, interested subclasses should override.
}

class ReconnectHandler extends Handler {

private int mPreviousAvailable = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ public DataAvailability hasDataAvailable(long offset, int size) {
return DataAvailability.AVAILABLE;
}

public void requestReadPosition(long offset) throws IOException {
// Empty implementation, interested subclasses should override.
}

public abstract void seek(long offset) throws IOException;

protected long peekLong(byte[] src, int offset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ public synchronized DataAvailability hasDataAvailable(long offset, int size) {
return toReturn;
}

@Override
public synchronized void requestReadPosition(long offset) throws IOException {
if (LOGS_ENABLED)
Log.d(TAG, "Request reconnect now at " + offset);

mCurrentOffset = offset;
mOffset = offset;

doCloseSync();
openConnectionsAndStreams();
}

public int getBuffering() {
int percentage = 0;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,20 +403,45 @@ public boolean parse() {
mMetaDataValues.put(MetaData.KEY_SEEK_AVAILABLE, 1);
mMetaDataValues.put(MetaData.KEY_NUM_TRACKS, mTracks.size());

updateAspectRatio();
if (parseOK) {
updateAspectRatio();

updateRotation();
updateRotation();

if (mCurrentAudioTrack != null) {
mCurrentAudioTrack.buildSampleTable();
}
if (mCurrentAudioTrack != null) {
mCurrentAudioTrack.buildSampleTable();
}

if (mCurrentVideoTrack != null) {
mCurrentVideoTrack.buildSampleTable();
}
if (mCurrentVideoTrack != null) {
mCurrentVideoTrack.buildSampleTable();
}

if (mCurrentSubtitleTrack != null) {
mCurrentSubtitleTrack.buildSampleTable();
}

if (mCurrentSubtitleTrack != null) {
mCurrentSubtitleTrack.buildSampleTable();
long firstOffset = 0;
if (mIsFragmented) {
firstOffset = mFirstMoofOffset;
} else {
if (mCurrentVideoTrack != null) {
firstOffset = mCurrentVideoTrack.getSampleTable().getOffset(0);
}

if (mCurrentAudioTrack != null) {
long audioOffset = mCurrentAudioTrack.getSampleTable().getOffset(0);
if (firstOffset == 0 || audioOffset < firstOffset) {
firstOffset = audioOffset;
}
}
}

if (mDataSource.hasDataAvailable(firstOffset, 1) == DataAvailability.NOT_AVAILABLE) {
try {
mDataSource.requestReadPosition(firstOffset);
} catch (IOException e) {
}
}
}

return parseOK;
Expand Down

0 comments on commit 43e0fa5

Please sign in to comment.