private void maybeSampleSyncParams(){
  long playbackPositionUs=audioTrackUtil.getPlaybackHeadPositionUs();
  if (playbackPositionUs == 0) {
    return;
  }
  if (log.allowVerbose()) {
    log.v("playbackPositionUs = " + playbackPositionUs);
  }
  long systemClockUs=System.nanoTime() / 1000;
  if (systemClockUs - lastPlayheadSampleTimeUs >= MIN_PLAYHEAD_OFFSET_SAMPLE_INTERVAL_US) {
    playheadOffsets[nextPlayheadOffsetIndex]=playbackPositionUs - systemClockUs;
    nextPlayheadOffsetIndex=(nextPlayheadOffsetIndex + 1) % MAX_PLAYHEAD_OFFSET_COUNT;
    if (playheadOffsetCount < MAX_PLAYHEAD_OFFSET_COUNT) {
      playheadOffsetCount++;
    }
    lastPlayheadSampleTimeUs=systemClockUs;
    smoothedPlayheadOffsetUs=0;
    for (int i=0; i < playheadOffsetCount; i++) {
      smoothedPlayheadOffsetUs+=playheadOffsets[i] / playheadOffsetCount;
    }
  }
  if (needsPassthroughWorkarounds()) {
    return;
  }
  if (systemClockUs - lastTimestampSampleTimeUs >= MIN_TIMESTAMP_SAMPLE_INTERVAL_US) {
    audioTimestampSet=audioTrackUtil.updateTimestamp();
    if (audioTimestampSet) {
      long audioTimestampUs=audioTrackUtil.getTimestampNanoTime() / 1000;
      if (log.allowVerbose()) {
        log.v("audioTimestampUs = " + audioTimestampUs);
      }
      long audioTimestampFramePosition=audioTrackUtil.getTimestampFramePosition();
      if (audioTimestampUs < resumeSystemTimeUs) {
        audioTimestampSet=false;
        log.w("The timestamp corresponds to a time before the track was most recently resumed: " + audioTimestampUs + ", "+ resumeSystemTimeUs);
      }
 else       if (Math.abs(audioTimestampUs - systemClockUs) > MAX_AUDIO_TIMESTAMP_OFFSET_US) {
        String message="Spurious audio timestamp (system clock mismatch): " + audioTimestampFramePosition + ", "+ audioTimestampUs+ ", "+ systemClockUs+ ", "+ playbackPositionUs;
        if (failOnSpuriousAudioTimestamp) {
          throw new InvalidAudioTrackTimestampException(message);
        }
        log.w(message);
        audioTimestampSet=false;
      }
 else       if (Math.abs(framesToDurationUs(audioTimestampFramePosition) - playbackPositionUs) > MAX_AUDIO_TIMESTAMP_OFFSET_US) {
        String message="Spurious audio timestamp (frame position mismatch): " + audioTimestampFramePosition + ", "+ audioTimestampUs+ ", "+ systemClockUs+ ", "+ playbackPositionUs;
        if (failOnSpuriousAudioTimestamp) {
          throw new InvalidAudioTrackTimestampException(message);
        }
        log.w(message);
        audioTimestampSet=false;
      }
    }
    if (isLatencyQuirkEnabled) {
      latencyUs=AmazonQuirks.getAudioHWLatency();
    }
 else     if (getLatencyMethod != null && !passthrough) {
      try {
        latencyUs=(Integer)getLatencyMethod.invoke(audioTrack,(Object[])null) * 1000L - bufferSizeUs;
        latencyUs=Math.max(latencyUs,0);
        if (latencyUs > MAX_LATENCY_US) {
          log.w("Ignoring impossibly large audio latency: " + latencyUs);
          latencyUs=0;
        }
      }
 catch (      Exception e) {
        getLatencyMethod=null;
      }
    }
    lastTimestampSampleTimeUs=systemClockUs;
  }
}

private void maybeSampleSyncParams ( ) { long playbackPositionUs = audioTrackUtil . getPlaybackHeadPositionUs ( ) ; if ( playbackPositionUs == 0 ) { return ; } if ( log . allowVerbose ( ) ) { log . v ( "playbackPositionUs = " + playbackPositionUs ) ; } long systemClockUs = System . nanoTime ( ) / 1000 ; if ( systemClockUs - lastPlayheadSampleTimeUs >= MIN_PLAYHEAD_OFFSET_SAMPLE_INTERVAL_US ) { playheadOffsets [ nextPlayheadOffsetIndex ] = playbackPositionUs - systemClockUs ; nextPlayheadOffsetIndex = ( nextPlayheadOffsetIndex + 1 ) % MAX_PLAYHEAD_OFFSET_COUNT ; if ( playheadOffsetCount < MAX_PLAYHEAD_OFFSET_COUNT ) { playheadOffsetCount ++ ; } lastPlayheadSampleTimeUs = systemClockUs ; smoothedPlayheadOffsetUs = 0 ; for ( int i = 0 ; i < playheadOffsetCount ; i ++ ) { smoothedPlayheadOffsetUs += playheadOffsets [ i ] / playheadOffsetCount ; } } if ( needsPassthroughWorkarounds ( ) ) { return ; } if ( systemClockUs - lastTimestampSampleTimeUs >= MIN_TIMESTAMP_SAMPLE_INTERVAL_US ) { audioTimestampSet = audioTrackUtil . updateTimestamp ( ) ; if ( audioTimestampSet ) { long audioTimestampUs = audioTrackUtil . getTimestampNanoTime ( ) / 1000 ; if ( log . allowVerbose ( ) ) { log . v ( "audioTimestampUs = " + audioTimestampUs ) ; } long audioTimestampFramePosition = audioTrackUtil . getTimestampFramePosition ( ) ; if ( audioTimestampUs < resumeSystemTimeUs ) { audioTimestampSet = false ; log . w ( "The timestamp corresponds to a time before the track was most recently resumed: " + audioTimestampUs + ", " + resumeSystemTimeUs ) ; } else if ( Math . abs ( audioTimestampUs - systemClockUs ) > MAX_AUDIO_TIMESTAMP_OFFSET_US ) { String message = "Spurious audio timestamp (system clock mismatch): " + audioTimestampFramePosition + ", " + audioTimestampUs + ", " + systemClockUs + ", " + playbackPositionUs ; if ( failOnSpuriousAudioTimestamp ) { throw new InvalidAudioTrackTimestampException ( message ) ; } log . w ( message ) ; audioTimestampSet = false ; } else if ( Math . abs ( framesToDurationUs ( audioTimestampFramePosition ) - playbackPositionUs ) > MAX_AUDIO_TIMESTAMP_OFFSET_US ) { String message = "Spurious audio timestamp (frame position mismatch): " + audioTimestampFramePosition + ", " + audioTimestampUs + ", " + systemClockUs + ", " + playbackPositionUs ; if ( failOnSpuriousAudioTimestamp ) { throw new InvalidAudioTrackTimestampException ( message ) ; } log . w ( message ) ; audioTimestampSet = false ; } } if ( isLatencyQuirkEnabled ) { latencyUs = AmazonQuirks . getAudioHWLatency ( ) ; } else if ( getLatencyMethod != null && ! passthrough ) { try { latencyUs = ( Integer ) getLatencyMethod . invoke ( audioTrack , ( Object [ ] ) null ) * 1000L - bufferSizeUs ; latencyUs = Math . max ( latencyUs , 0 ) ; if ( latencyUs > MAX_LATENCY_US ) { log . w ( "Ignoring impossibly large audio latency: " + latencyUs ) ; latencyUs = 0 ; } } catch ( Exception e ) { getLatencyMethod = null ; } } lastTimestampSampleTimeUs = systemClockUs ; } }
updates the audio track latency and playback position parameters .
