@Test
public void testSetSampleOffsetBetweenSamples() {

  writeTestData();
  long sampleOffsetUs = 1000;
  sampleQueue.setSampleOffsetUs(sampleOffsetUs);
  // Write a final sample now the offset is set.
  long unadjustedTimestampUs = LAST_SAMPLE_TIMESTAMP + 1234;
  writeSample(DATA, unadjustedTimestampUs, /* sampleFlags= */ 0);
  assertReadTestData();
  // We expect to read the format adjusted to account for the sample offset, followed by the final
  // sample and then the end of stream.
  assertReadFormat(
      /* formatRequired= */ false, FORMAT_2.copyWithSubsampleOffsetUs(sampleOffsetUs));
  assertReadSample(
      unadjustedTimestampUs + sampleOffsetUs,
      /* isKeyFrame= */ false,
      /* isEncrypted= */ false,
      DATA,
      /* offset= */ 0,
      DATA.length);
  assertReadEndOfStream(/* formatRequired= */ false);
}