Exoplayer: SeekMap.getPosition implementations have side effects

Created on 7 Dec 2016  路  4Comments  路  Source: google/ExoPlayer

See the bolded line of code:
_Mp4Extractor.java_

@Override
  public long getPosition(long timeUs) {
    long earliestSamplePosition = Long.MAX_VALUE;
    for (Mp4Track track : tracks) {
      TrackSampleTable sampleTable = track.sampleTable;
      int sampleIndex = sampleTable.getIndexOfEarlierOrEqualSynchronizationSample(timeUs);
      if (sampleIndex == C.INDEX_UNSET) {
        // Handle the case where the requested time is before the first synchronization sample.
        sampleIndex = sampleTable.getIndexOfLaterOrEqualSynchronizationSample(timeUs);
      }
      **track.sampleIndex = sampleIndex;**

      long offset = sampleTable.offsets[sampleIndex];
      if (offset < earliestSamplePosition) {
        earliestSamplePosition = offset;
      }
    }
    return earliestSamplePosition;
  }

A getter changes the state of the object?

I've spent 2 hours trying to figure out why CacheEvictor.OnSpanTouched(Cache, CacheSpan, CacheSpan)was called after I try to retrieve the current position in bytes (by casting my current Extractor to a seekMap and calling SeekMap .getPosition(long))

Is this by design? If yes, then I hope it'll be rethinked.. and meanwhile, how can I get the current position as the offset in bytes? I can modify the source file, but is there a more elegant way?

Thanks

bug

All 4 comments

That doesn't look right, so I suspect it's a bug. @andrewlewis can confirm.

I just put another method getPosition_NoStateChange() for now with that line removed and everything's working properly.
I almost finished an Evictor that removes the _furthest_ CacheSpans from the current position, rather than the _oldest_. It's way better than the default Lru approach. I can make a pull request for it if you think it'll be useful for others, but for now it only works with Mp4Extractor(in fact, it only needs the SeekMap.getPosition(long) implementation); and it requires someone to tell it the current position (currently, I'm using the exoplayer instance for this)

FlacOggSeeker and OggSeekMap also have unwanted side effects. We'll be merging fixes for these two (and also for Mp4Extractor) into dev-v2 shortly. The changes will not be backported to dev-v1 because it requires touching quite a lot of files.

Fixed in dev-v2.

Was this page helpful?
0 / 5 - 0 ratings