Program: 110455
Project: 110455
Buggy source:
/** 
 * Updates the audio track latency and playback position parameters. 
 */
private void maybeSampleSyncParams(){
  long playbackPositionUs=audioTrackUtil.getPlaybackHeadPositionUs();
  if (playbackPositionUs == 0) {
    return;
  }
  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 (systemClockUs - lastTimestampSampleTimeUs >= MIN_TIMESTAMP_SAMPLE_INTERVAL_US) {
    audioTimestampSet=audioTrackUtil.updateTimestamp();
    if (audioTimestampSet) {
      long audioTimestampUs=audioTrackUtil.getTimestampNanoTime() / 1000;
      long audioTimestampFramePosition=audioTrackUtil.getTimestampFramePosition();
      if (audioTimestampUs < resumeSystemTimeUs) {
        audioTimestampSet=false;
      }
 else       if (Math.abs(audioTimestampUs - systemClockUs) > MAX_AUDIO_TIMESTAMP_OFFSET_US) {
        audioTimestampSet=false;
        Log.w(TAG,"String_Node_Str" + audioTimestampFramePosition + "String_Node_Str"+ audioTimestampUs+ "String_Node_Str"+ systemClockUs+ "String_Node_Str"+ playbackPositionUs);
      }
 else       if (Math.abs(framesToDurationUs(audioTimestampFramePosition) - playbackPositionUs) > MAX_AUDIO_TIMESTAMP_OFFSET_US) {
        audioTimestampSet=false;
        Log.w(TAG,"String_Node_Str" + audioTimestampFramePosition + "String_Node_Str"+ audioTimestampUs+ "String_Node_Str"+ systemClockUs+ "String_Node_Str"+ playbackPositionUs);
      }
    }
    if (getLatencyMethod != null) {
      try {
        latencyUs=(Integer)getLatencyMethod.invoke(audioTrack,(Object[])null) * 1000L - framesToDurationUs(bytesToFrames(bufferSize));
        latencyUs=Math.max(latencyUs,0);
        if (latencyUs > MAX_LATENCY_US) {
          Log.w(TAG,"String_Node_Str" + latencyUs);
          latencyUs=0;
        }
      }
 catch (      Exception e) {
        getLatencyMethod=null;
      }
    }
    lastTimestampSampleTimeUs=systemClockUs;
  }
}

Fixed version (ground truth):
/** 
 * Updates the audio track latency and playback position parameters. 
 */
private void maybeSampleSyncParams(){
  long playbackPositionUs=audioTrackUtil.getPlaybackHeadPositionUs();
  if (playbackPositionUs == 0) {
    return;
  }
  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 (systemClockUs - lastTimestampSampleTimeUs >= MIN_TIMESTAMP_SAMPLE_INTERVAL_US) {
    audioTimestampSet=!isAc3 && audioTrackUtil.updateTimestamp();
    if (audioTimestampSet) {
      long audioTimestampUs=audioTrackUtil.getTimestampNanoTime() / 1000;
      long audioTimestampFramePosition=audioTrackUtil.getTimestampFramePosition();
      if (audioTimestampUs < resumeSystemTimeUs) {
        audioTimestampSet=false;
      }
 else       if (Math.abs(audioTimestampUs - systemClockUs) > MAX_AUDIO_TIMESTAMP_OFFSET_US) {
        audioTimestampSet=false;
        Log.w(TAG,"String_Node_Str" + audioTimestampFramePosition + "String_Node_Str"+ audioTimestampUs+ "String_Node_Str"+ systemClockUs+ "String_Node_Str"+ playbackPositionUs);
      }
 else       if (Math.abs(framesToDurationUs(audioTimestampFramePosition) - playbackPositionUs) > MAX_AUDIO_TIMESTAMP_OFFSET_US) {
        audioTimestampSet=false;
        Log.w(TAG,"String_Node_Str" + audioTimestampFramePosition + "String_Node_Str"+ audioTimestampUs+ "String_Node_Str"+ systemClockUs+ "String_Node_Str"+ playbackPositionUs);
      }
    }
    if (getLatencyMethod != null) {
      try {
        latencyUs=(Integer)getLatencyMethod.invoke(audioTrack,(Object[])null) * 1000L - framesToDurationUs(bytesToFrames(bufferSize));
        latencyUs=Math.max(latencyUs,0);
        if (latencyUs > MAX_LATENCY_US) {
          Log.w(TAG,"String_Node_Str" + latencyUs);
          latencyUs=0;
        }
      }
 catch (      Exception e) {
        getLatencyMethod=null;
      }
    }
    lastTimestampSampleTimeUs=systemClockUs;
  }
}