ConstantBitrateSeekMap implements SeekMap { @Override public SeekPoints getSeekPoints(long timeUs) { if (dataSize == C.LENGTH_UNSET) { return new SeekPoints(new SeekPoint(0, firstFrameBytePosition)); } long seekFramePosition = getFramePositionForTimeUs(timeUs); long seekTimeUs = getTimeUsAtPosition(seekFramePosition); SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekFramePosition); if (seekTimeUs >= timeUs || seekFramePosition + frameSize >= inputLength) { return new SeekPoints(seekPoint); } else { long secondSeekPosition = seekFramePosition + frameSize; long secondSeekTimeUs = getTimeUsAtPosition(secondSeekPosition); SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition); return new SeekPoints(seekPoint, secondSeekPoint); } } ConstantBitrateSeekMap(
      long inputLength, long firstFrameBytePosition, int bitrate, int frameSize); @Override boolean isSeekable(); @Override SeekPoints getSeekPoints(long timeUs); @Override long getDurationUs(); long getTimeUsAtPosition(long position);  }
@Test public void testGetSeekPoints_forSeekableInput_forSeekPointAtSyncPosition_return1SeekPoint() { constantBitrateSeekMap = new ConstantBitrateSeekMap( 2_300, 100, 8_000, 100); SeekMap.SeekPoints seekPoints = constantBitrateSeekMap.getSeekPoints( 1_200_000); assertThat(seekPoints.first.timeUs).isEqualTo(1_200_000); assertThat(seekPoints.first.position).isEqualTo(1300); assertThat(seekPoints.second).isEqualTo(seekPoints.first); }
@Test public void testGetSeekPoints_forSeekableInput_forNonSyncSeekPosition_return2SeekPoints() { constantBitrateSeekMap = new ConstantBitrateSeekMap( 2_300, 100, 8_000, 100); SeekMap.SeekPoints seekPoints = constantBitrateSeekMap.getSeekPoints( 345_678); assertThat(seekPoints.first.timeUs).isEqualTo(300_000); assertThat(seekPoints.first.position).isEqualTo(400); assertThat(seekPoints.second.timeUs).isEqualTo(400_000); assertThat(seekPoints.second.position).isEqualTo(500); }
@Test public void testGetSeekPoints_forSeekableInput_forSeekPointWithinLastFrame_return1SeekPoint() { constantBitrateSeekMap = new ConstantBitrateSeekMap( 2_300, 100, 8_000, 100); SeekMap.SeekPoints seekPoints = constantBitrateSeekMap.getSeekPoints( 2_123_456); assertThat(seekPoints.first.timeUs).isEqualTo(2_100_000); assertThat(seekPoints.first.position).isEqualTo(2_200); assertThat(seekPoints.second).isEqualTo(seekPoints.first); }
@Test public void testGetSeekPoints_forSeekableInput_forSeekPointAtEndOfStream_return1SeekPoint() { constantBitrateSeekMap = new ConstantBitrateSeekMap( 2_300, 100, 8_000, 100); SeekMap.SeekPoints seekPoints = constantBitrateSeekMap.getSeekPoints( 2_200_000); assertThat(seekPoints.first.timeUs).isEqualTo(2_100_000); assertThat(seekPoints.first.position).isEqualTo(2_200); assertThat(seekPoints.second).isEqualTo(seekPoints.first); }
@Test public void testGetSeekPoints_forUnseekableInput_returnSeekPoint0() { int firstBytePosition = 100; constantBitrateSeekMap = new ConstantBitrateSeekMap( C.LENGTH_UNSET, firstBytePosition, 8_000, 100); SeekMap.SeekPoints seekPoints = constantBitrateSeekMap.getSeekPoints( 123); assertThat(seekPoints.first.timeUs).isEqualTo(0); assertThat(seekPoints.first.position).isEqualTo(firstBytePosition); assertThat(seekPoints.second).isEqualTo(seekPoints.first); }
@Test public void testGetSeekPoints_forSeekableInput_forSyncPosition0_return1SeekPoint() { int firstBytePosition = 100; constantBitrateSeekMap = new ConstantBitrateSeekMap( 2_300, firstBytePosition, 8_000, 100); SeekMap.SeekPoints seekPoints = constantBitrateSeekMap.getSeekPoints( 0); assertThat(seekPoints.first.timeUs).isEqualTo(0); assertThat(seekPoints.first.position).isEqualTo(firstBytePosition); assertThat(seekPoints.second).isEqualTo(seekPoints.first); }