Program: 110456
Project: 110456
Buggy source:
/** 
 * Attempts to write   {@code size} bytes from {@code buffer} at {@code offset} to the audio track.Returns a bit field containing  {@link #RESULT_BUFFER_CONSUMED} if the buffer can be released(due to having been written), and  {@link #RESULT_POSITION_DISCONTINUITY} if the buffer wasdiscontinuous with previously written data.
 * @param buffer The buffer containing audio data to play back.
 * @param offset The offset in the buffer from which to consume data.
 * @param size The number of bytes to consume from {@code buffer}.
 * @param presentationTimeUs Presentation timestamp of the next buffer in microseconds.
 * @return A bit field with {@link #RESULT_BUFFER_CONSUMED} if the buffer can be released, and{@link #RESULT_POSITION_DISCONTINUITY} if the buffer was not contiguous with previouslywritten data.
 * @throws WriteException If an error occurs writing the audio data.
 */
public int handleBuffer(ByteBuffer buffer,int offset,int size,long presentationTimeUs) throws WriteException {
  if (size == 0) {
    return RESULT_BUFFER_CONSUMED;
  }
  if (Util.SDK_INT <= 22 && isAc3 && audioTrack.getPlayState() == android.media.AudioTrack.PLAYSTATE_PAUSED) {
    return 0;
  }
  int result=0;
  if (temporaryBufferSize == 0) {
    if (isAc3 && ac3Bitrate == UNKNOWN_AC3_BITRATE) {
      ac3Bitrate=Ac3Util.getBitrate(size,sampleRate);
    }
    long bufferStartTime=presentationTimeUs - framesToDurationUs(bytesToFrames(size));
    if (startMediaTimeUs == START_NOT_SET) {
      startMediaTimeUs=Math.max(0,bufferStartTime);
      startMediaTimeState=START_IN_SYNC;
    }
 else {
      long expectedBufferStartTime=startMediaTimeUs + framesToDurationUs(bytesToFrames(submittedBytes));
      if (startMediaTimeState == START_IN_SYNC && Math.abs(expectedBufferStartTime - bufferStartTime) > 200000) {
        Log.e(TAG,"String_Node_Str" + expectedBufferStartTime + "String_Node_Str"+ bufferStartTime+ "String_Node_Str");
        startMediaTimeState=START_NEED_SYNC;
      }
      if (startMediaTimeState == START_NEED_SYNC) {
        startMediaTimeUs+=(bufferStartTime - expectedBufferStartTime);
        startMediaTimeState=START_IN_SYNC;
        result|=RESULT_POSITION_DISCONTINUITY;
      }
    }
  }
  if (temporaryBufferSize == 0) {
    temporaryBufferSize=size;
    buffer.position(offset);
    if (Util.SDK_INT < 21) {
      if (temporaryBuffer == null || temporaryBuffer.length < size) {
        temporaryBuffer=new byte[size];
      }
      buffer.get(temporaryBuffer,0,size);
      temporaryBufferOffset=0;
    }
  }
  int bytesWritten=0;
  if (Util.SDK_INT < 21) {
    int bytesPending=(int)(submittedBytes - (audioTrackUtil.getPlaybackHeadPosition() * frameSize));
    int bytesToWrite=bufferSize - bytesPending;
    if (bytesToWrite > 0) {
      bytesToWrite=Math.min(temporaryBufferSize,bytesToWrite);
      bytesWritten=audioTrack.write(temporaryBuffer,temporaryBufferOffset,bytesToWrite);
      if (bytesWritten >= 0) {
        temporaryBufferOffset+=bytesWritten;
      }
    }
  }
 else {
    bytesWritten=writeNonBlockingV21(audioTrack,buffer,temporaryBufferSize);
  }
  if (bytesWritten < 0) {
    throw new WriteException(bytesWritten);
  }
  temporaryBufferSize-=bytesWritten;
  submittedBytes+=bytesWritten;
  if (temporaryBufferSize == 0) {
    result|=RESULT_BUFFER_CONSUMED;
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Attempts to write   {@code size} bytes from {@code buffer} at {@code offset} to the audio track.Returns a bit field containing  {@link #RESULT_BUFFER_CONSUMED} if the buffer can be released(due to having been written), and  {@link #RESULT_POSITION_DISCONTINUITY} if the buffer wasdiscontinuous with previously written data.
 * @param buffer The buffer containing audio data to play back.
 * @param offset The offset in the buffer from which to consume data.
 * @param size The number of bytes to consume from {@code buffer}.
 * @param presentationTimeUs Presentation timestamp of the next buffer in microseconds.
 * @return A bit field with {@link #RESULT_BUFFER_CONSUMED} if the buffer can be released, and{@link #RESULT_POSITION_DISCONTINUITY} if the buffer was not contiguous with previouslywritten data.
 * @throws WriteException If an error occurs writing the audio data.
 */
public int handleBuffer(ByteBuffer buffer,int offset,int size,long presentationTimeUs) throws WriteException {
  if (size == 0) {
    return RESULT_BUFFER_CONSUMED;
  }
  if (Util.SDK_INT <= 22 && isAc3) {
    if (audioTrack.getPlayState() == android.media.AudioTrack.PLAYSTATE_PAUSED) {
      return 0;
    }
    if (audioTrack.getPlayState() == android.media.AudioTrack.PLAYSTATE_STOPPED && audioTrackUtil.getPlaybackHeadPosition() != 0) {
      return 0;
    }
  }
  int result=0;
  if (temporaryBufferSize == 0) {
    if (isAc3 && ac3Bitrate == UNKNOWN_AC3_BITRATE) {
      ac3Bitrate=Ac3Util.getBitrate(size,sampleRate);
    }
    long bufferStartTime=presentationTimeUs - framesToDurationUs(bytesToFrames(size));
    if (startMediaTimeUs == START_NOT_SET) {
      startMediaTimeUs=Math.max(0,bufferStartTime);
      startMediaTimeState=START_IN_SYNC;
    }
 else {
      long expectedBufferStartTime=startMediaTimeUs + framesToDurationUs(bytesToFrames(submittedBytes));
      if (startMediaTimeState == START_IN_SYNC && Math.abs(expectedBufferStartTime - bufferStartTime) > 200000) {
        Log.e(TAG,"String_Node_Str" + expectedBufferStartTime + "String_Node_Str"+ bufferStartTime+ "String_Node_Str");
        startMediaTimeState=START_NEED_SYNC;
      }
      if (startMediaTimeState == START_NEED_SYNC) {
        startMediaTimeUs+=(bufferStartTime - expectedBufferStartTime);
        startMediaTimeState=START_IN_SYNC;
        result|=RESULT_POSITION_DISCONTINUITY;
      }
    }
  }
  if (temporaryBufferSize == 0) {
    temporaryBufferSize=size;
    buffer.position(offset);
    if (Util.SDK_INT < 21) {
      if (temporaryBuffer == null || temporaryBuffer.length < size) {
        temporaryBuffer=new byte[size];
      }
      buffer.get(temporaryBuffer,0,size);
      temporaryBufferOffset=0;
    }
  }
  int bytesWritten=0;
  if (Util.SDK_INT < 21) {
    int bytesPending=(int)(submittedBytes - (audioTrackUtil.getPlaybackHeadPosition() * frameSize));
    int bytesToWrite=bufferSize - bytesPending;
    if (bytesToWrite > 0) {
      bytesToWrite=Math.min(temporaryBufferSize,bytesToWrite);
      bytesWritten=audioTrack.write(temporaryBuffer,temporaryBufferOffset,bytesToWrite);
      if (bytesWritten >= 0) {
        temporaryBufferOffset+=bytesWritten;
      }
    }
  }
 else {
    bytesWritten=writeNonBlockingV21(audioTrack,buffer,temporaryBufferSize);
  }
  if (bytesWritten < 0) {
    throw new WriteException(bytesWritten);
  }
  temporaryBufferSize-=bytesWritten;
  submittedBytes+=bytesWritten;
  if (temporaryBufferSize == 0) {
    result|=RESULT_BUFFER_CONSUMED;
  }
  return result;
}