Skip to content

Commit

Permalink
fix artifacts video
Browse files Browse the repository at this point in the history
  • Loading branch information
jumperson authored and natario1 committed Aug 11, 2024
1 parent 0a415ba commit 619dbb5
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ public void initialize() {
}
}

// Fetch the start timestamp. Only way to do this is select tracks.
// This is very important to have a timebase e.g. for seeks that happen before any read.
for (int i = 0; i < mExtractor.getTrackCount(); i++) mExtractor.selectTrack(i);
mOriginUs = mExtractor.getSampleTime();
LOG.v("initialize(): found origin=" + mOriginUs);
for (int i = 0; i < mExtractor.getTrackCount(); i++) mExtractor.unselectTrack(i);
mInitialized = true;

// Debugging mOriginUs issues.
Expand Down Expand Up @@ -141,6 +135,8 @@ public void releaseTrack(@NonNull TrackType type) {

@Override
public long seekTo(long desiredPositionUs) {
initializeMOriginUsIfNotYet();

boolean hasVideo = mSelectedTracks.contains(TrackType.VIDEO);
boolean hasAudio = mSelectedTracks.contains(TrackType.AUDIO);
LOG.i("seekTo(): seeking to " + (mOriginUs + desiredPositionUs)
Expand Down Expand Up @@ -193,6 +189,9 @@ public boolean canReadTrack(@NonNull TrackType type) {

@Override
public void readTrack(@NonNull Chunk chunk) {
// Must be called if not to seek.
initializeMOriginUsIfNotYet();

int index = mExtractor.getSampleTrackIndex();

int position = chunk.buffer.position();
Expand Down Expand Up @@ -236,7 +235,7 @@ public void readTrack(@NonNull Chunk chunk) {

@Override
public long getPositionUs() {
if (!isInitialized()) return 0;
if (!isInitializedOriginUs()) return 0;

// Return the fastest track.
// This ensures linear behavior over time: if a track is behind the other,
Expand Down Expand Up @@ -289,4 +288,14 @@ public MediaFormat getTrackFormat(@NonNull TrackType type) {
LOG.i("getTrackFormat(" + type + ")");
return mFormat.getOrNull(type);
}

private boolean isInitializedOriginUs() {
return mOriginUs != Long.MIN_VALUE;
}

private void initializeMOriginUsIfNotYet() {
if (!isInitializedOriginUs()) {
mOriginUs = mExtractor.getSampleTime();
}
}
}

0 comments on commit 619dbb5

Please sign in to comment.